I'm new to C, and have been staring at this code for a while:
void readEntireFile(){
int ch;
FILE *fp; // pointer to a file type
fp = fopen("/some/path/file", "r"); // Change to match your path
ch = getc(fp);
while (ch != EOF){ // keep looping until End Of File
putchar(ch); // print the characters read
ch = getc(fp);
}
fclose(fp);
}
This function creates a pointer to a file, gets the first character, and as long as the character isn't an EOF char, prints the char. This continues until the EOF character is reached.
My question here is simple: how come the pointer continues to point to the next character each time? I can't see how it's incremented, and am getting really confused!
EDIT: in addition the answer below, this question also helped me understand.