Search through a file & return a pointer?
Hi,
Are there any functions similar to strstr() that can search through a file and return a pointer to that location, so i can then read in the data to a buffer?
Example..
Code:
FILE* fFile;
fFile = fopen("Test.dat");
int iLocation = look_through_file(fFile, "XPR0");
etc etc..
If not how would one get the location of such a string in a file?
Thanks
Re: Search through a file & return a pointer?
Quote:
Originally posted by Marc
Hi,
Are there any functions similar to strstr() that can search through a file and return a pointer to that location, so i can then read in the data to a buffer?
Example..
Code:
FILE* fFile;
fFile = fopen("Test.dat");
int iLocation = look_through_file(fFile, "XPR0");
etc etc..
If not how would one get the location of such a string in a file?
Thanks
The only way to search through a file is to read the file, so no. You'll have to read the file from the beginning and search thru the buffer for what you're looking for.
But it IS possible to read the bytes directly at, say, 100 thru 125. You need lseek() or a related function.