I need to be able to prompt the user to input text, which is then taken and inputed into a text file. It then stops reading once the user enters CRTL-D/fputs returns NULL.
I can open a file and use fprintf to write to it, but now I need to write to the file using user input. I don't really know where to start.
I know how to read a .txt file and print its contents to the terminal using fputs, but writing to one through the terminal is too confusing for me...
int main(int argc, char *argv[]) {
FILE *f;
f = fopen(argv[1], "w");
if (errno) {
perror("Error opening file.");
exit(1);
}
fprintf(f, "Hello, Jake.\n");
fclose(f);
}
I need a while loop that ends once the fputs or feof returns NULL.
If at any point I have said something that doesn't make sense, it's because I am confused. Learning C for uni is driving me nuts :(