I need to write something into a txt file and read the contents, then print them on the screen. Below is the code I have written, it can create and write contents into file
char c;
is your first problem. getc
and getchar
return int
s, not a char
s. Read the man page carefully and change that local to:
int c;
You're also not resetting the inFile
stream after the writes. Put something like:
fseek(inFile, 0L, SEEK_SET);
before you start reading from that stream. (See the man page.)
Lastly, your main signature is not standard. Use:
int main(void) { ...