On December 15, 2005 04:41 pm, Vasilkov Vasily wrote:
> Hi all..
>     this is the part of my source
> ************
>     FILE *source;
>     source = fopen("/home/user/test.c", "r");
>     if (source) {
>       printf("fopen error");
>       exit(0);
>     };
> ************
>   file "/home/user/test.c" exists and its access mode is 777..., but
>   when I run program, I get "fopen error" message...
>
>   Can anybody explain me this subj?
>
>

From man fopen:

RETURN VALUES
     Upon successful completion fopen(), fdopen() and freopen() return a FILE
     pointer.  Otherwise, NULL is returned and the global variable errno is
     set to indicate the error.

That means that your code should be:

     FILE *source;
     source = fopen("/home/user/test.c", "r");
     if (!source) {
       printf("fopen error");
       exit(0);
     };

Nicolas.

-- 
FreeBSD 7.0-CURRENT #4: Sat Dec 10 11:55:08 EST 2005     
[EMAIL PROTECTED]:/usr/obj/usr/src/sys/CLK01A 
PGP? (updated 16 Nov 05) : http://www.clkroot.net/security/nb_root.asc

Attachment: pgp4AJwFcAyhT.pgp
Description: PGP signature

Reply via email to