0

i need help with understanding this file function in c

I need to calculate the number of letter in a text per average but i cant figure out how to use this file function (which is mandatory) . #include <stdio.h> void writeToFile() { FILE *f = fopen("text.txt", "w"); char c; while((c = getchar()) != '#') { fputc(c, f); } fclose(f); } int main() { writeToFile(); // your code here }

27th Dec 2020, 7:34 PM
Mihail
Mihail - avatar
1 Resposta
+ 1
the 'writeToFile' function write the user input in 'text.txt' file and stop when the character '#' is typed. so in the main function, you should open that 'text.txt' file in reading mode and then read it with 'fgetc' to do what your asked to do.
27th Dec 2020, 8:29 PM
John Robotane
John Robotane - avatar