"fopen" call...

Nicolas Blais nb_root at videotron.ca
Thu Dec 15 13:47:25 PST 2005


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     
root at clk01a:/usr/obj/usr/src/sys/CLK01A 
PGP? (updated 16 Nov 05) : http://www.clkroot.net/security/nb_root.asc
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20051215/fc966697/attachment.bin


More information about the freebsd-questions mailing list