Help for fopen()

Angelo Fraietta newsgroups at smartcontroller.com.au
Tue Jul 31 23:00:06 UTC 2007


Kate Feng wrote:

> I must have missed some simple setup steps  that
> fopen() does not seem to work anymore.
> 
> fopen("mydir/test.dat","w") returns error 2 : "/* No such file or
> directory */"
> 
> even though it does exist.
> 
> fopen("test.dat","w") returns a file descriptor and
> no error message.  However, "test.dat" does not exist.
> Even if  "test.dat" exists and is world writable, it
> does not seem to respond to the following
> 
> 
> fprintf(fp, "test\n");
>   fflush(fp);
>   fsync(fileno(fp));
>   fclose(fp);
> 
> The file still remains empty and  untouched.
> 

First try this

   FILE* fp = fopen("/test.dat","w");
   if (fp)
   {
     fprintf(fp, "test\n");
     fflush(fp);
     fsync(fileno(fp));
     fclose(fp);

     /* Now reopen and read */
     fp = fopen("/test.dat","r");
     ... bla bla bla - you can do the read code and print to console
   }

What do you get? Is teh file still empty?

-- 
Dr Angelo Fraietta
A.Eng, A.Mus.A, BA(Hons), Ph.D.

PO Box 859
Hamilton NSW 2303

Home Page


http://www.smartcontroller.com.au/~angelo/

There are those who seek knowledge for the sake of knowledge - that is 
CURIOSITY
There are those who seek knowledge to be known by others - that is VANITY
There are those who seek knowledge in order to serve - that is LOVE
     Bernard of Clairvaux (1090 - 1153)




More information about the users mailing list