Is there a way to find the character stored in file pointer without fgetc.
Say I have a word “steve jobs” in a file called apple.txt is there something like
int main(int argc,char *argv[])
{
FILE *fp=fopen("apple.txt","r");
if(fp=='s'&&(fp+2)=='e')
printf("steve is there");
else
printf("Steve not there");
fclose(fp);
}
Clearly this doesn’t really work! It just prints something like C forbids comparison b/n pointer n int. Even i tried adding * in front of (fp+2) and fp, it said no match for operator==
I believe the function fgetc(FILE *) works in such a way that it gets the unsigned char and then moves the pointer to the next location. Is there any function to just get the character without moving the pointer and also is the above code possible in any other way?!
You might use
getcandungetc. Read the documentation about it (you can only have one push-back character).On some systems (notably Posix systems like Linux) you have the ability to map into memory a portion of a file. Read more about the
mmapsystem call which enables you to see a portion of a file as segment of memory. (mmapis not usable on non-seekable files like pipes or sockets; it basically works mostly on “disk” files).