Need Help with fscanf, a bit confused
I just started doing programming, and have been trying to self-learn and i have hit some obstacles. Maybe someone can help?
In data in/out onto a text file;
To put something onto a text file, I know, we can use fprintf; For example, if i want to open a file named test, and want to put "hello hi" into it, I can use the following code:
Code:
#include <stdio.h>
int main()
{
FILE *myfile;
myfile=fopen("test.txt", "w");
fprintf(myfile, "Hello Hi \n");
fclose (myfile);
return 0;
}
But, what if I wanted the user to input something, then i put that something in the text file. For example: I ask the user for his name, he inputs: "John Deere". How do i put "John Deere" into the text file?
I would really appreciate the help, if anyone can write me a simple code for that scenario. Thanks a lot in advance.