not writing to file
- From: John Smith <jsmith@xxxxxxxxxxx>
- Date: Mon, 30 Oct 2006 19:44:05 -0500
I try to write some data to a file. After some data had supposedly
been written to the file, I opened the file before the program
closed it and found it empty. What's wrong with my code? Thanks.
-----------only the relevant code is listed-----------------
FILE *lptr
char *name;
int nNo;
..............
..............
lptr=fopen("myfile","w")
...............
...............
/* deep in a function */
sprintf(buffer, "%s\r\n",name);
printf("No is %d. Name is %s\n",nNo,buffer);
/* they printed OK on screen, my way of checking things */
fwrite (name , 1 , sizeof(name) , lptr);
fwrite (&nNo , 1 , sizeof(nNo) , lptr);
/* checked file without waiting for it to close and
/* found nothing in the file. It's empty. Why? */
...............
...............
fclose(lptr);
.
- Follow-Ups:
- Re: not writing to file
- From: Herbert Rosenau
- Re: not writing to file
- From: Jens Thoms Toerring
- Re: not writing to file
- From: Adrian
- Re: not writing to file
- Prev by Date: Re: pointer to an array -Is there an out of bound access?
- Next by Date: Re: not writing to file
- Previous by thread: Triangular Matrix
- Next by thread: Re: not writing to file
- Index(es):