I am trying to learn C, and am currently working on a toy script. Right now, it simply opens a text file, reads it char by char, and spits it out onto the command line.
char tmp = getc(fp); //current letter in file
int i=0;
while (tmp != EOF) //End-Of-File (defined in stdio.h)
You need to check the value returned by getc
for EOF
. Instead, you convert it to a char
and then check whether that's equal to EOF
converted to a char
. But what if the value of char
that converts to EOF
is actually in the file? Check the docs, getc
returns an int
.
You have other mistakes as well.