not writing to file



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);
.