-   Programming (
-   -   C prog..except input ,write to textfile?? (

kato678 02-21-2002 12:41 AM

C prog..except input ,write to textfile??
Hi. Really new to Linux and a wee bit familiar with C. I want to write a small code that will ask user his/her name when run and then write it to a text file called name.txt . that's it.
brian :)

i know the C code part but I dont know how I would write to a text file on the disk. I mean I know the printf, scanf parts, etc

thnks again.

Malicious 02-21-2002 01:09 AM

scanf() will handle the input. To write to a file on disk, you must open a file and use fprintf()

char *nm = "Malicious";
FILE *nf;

/* open a file in the current working
directory named "names.txt" */
nf = fopen("names.txt", "w");
/* write a name to it */
fprintf(nf, "%s\n", nm);
/* close it */

Let me know when you need some more homework done. :-)

All times are GMT -5. The time now is 02:30 PM.