On Tue, Aug 5, 2008 at 2:27 PM, Bill Cunningham <[EMAIL PROTECTED]> wrote:
>    Here is the complete sources and what the compile spits out at compile
> time.
>
> #include <stdio.h>
> #include <stdlib.h>
>
> int main (void) {
>       FILE *fp;
>       char a[]="hello\n";
>       fp=fopen("file","a");
>       if (fp==NULL) {
>          puts("open error");
>          exit(EXIT_FAILURE);
>          }
>       fprintf(fp,"%s",a);
>       fclose(fp);
>       if (fp==EOF) {
>           puts("close error");
>           exit(EXIT_FAILURE);
>           }
> return 0;
> }
>
> gcc: 2: No such file or directory
> p.c: In function `main':
> p.c:14: warning: comparison between pointer and integer

Yes, you are comparing EOF (which is NOT a pointer, it's usually -1)
to fp (which is a pointer). Not sure why you are doing that
comparison, since it would not indicate any kind of error anyway. It
would be more correct to check what is returned from fclose to see if
EBADF is returned (bad file descriptor). flclose() also will set the
global variable errno if necessary.

-- Brett
------------------------------------------------------------
"In the rhythm of music a secret is hidden;
 If I were to divulge it, it would overturn the world."
 -- Jelaleddin Rumi

Reply via email to