[prev] 33 [next]

Exercise 2: Opening/Closing Files

If abc is an existing file
  • why is  fopen("abc","w")  potentially bad?
  • why is  fopen("abc","a")  potentially better?

What will be the output from ...

FILE *in;  int ch;
while (1) {
   if ((in = fopen("abc", "r")) == NULL){
        error(1,errno,NULL);
   }
      
   while ((ch = fgetc(in)) != EOF)
      putc(ch, stdout);
}