I wrote this program:


Code:
#include <stdio.h>
#include <stdlib.h>

main(  )
{
FILE *fin = fopen("C:orig.c"," rb"), *fout = fopen("C:dest.c","ab") ;
int ch,x=1;

if ((fin==NULL) || (fout==NULL))
printf("%s\n",NULL);

while ((ch=fgetc(fin))!=EOF)
 fputc(ch,fout);
 
 
  while((ch = fgetc(fout))!=EOF)
 putchar(ch);
 
 
 
 fclose(fin);
fclose(fout);

}


It is currently in the Files folder, inside the C folder that is in the Desktop. If I move the program.c file to the desktop, open it and run it with the compiler, an empty dest.c file (and the executable of the program) is created in the desktop. If I change orig.c's "rb" to "ab" the same happens to orig.c.

But if I don't, what is exactly happening to orig.c? Is it being created elsewhere as an empty file or, since it doesn't exist in the current folder, dest.c is an empty file? What is exactly happening here?
This is likely a permissions issue, change the file you are writing to a different location such as the desktop or a folder on the C drive which you are setup to have full permissions for.
What do you mean? dest.c is an empty file because I don't have permission to read orig.c in the desktop folder, because it doesn't exist there?

I know how to solve the problem, I just have to change the path "C: dest.c" to the full path, because this way it looks for the specified file in the folder the program is in.
AliceIsDead wrote:
What do you mean? dest.c is an empty file because I don't have permission to read orig.c in the desktop folder, because it doesn't exist there?

I know how to solve the problem, I just have to change the path "C: dest.c" to the full path, because this way it looks for the specified file in the folder the program is in.


I guess it was assumed that was the full path, as that is what is usually specified there. Smile
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement