fread
returns the number of items read. In your case size is l
, and the number is 1
. fread will return 1. Swap the arguments l and 1.
If you really want to look for an ascii string inside a binary file you can do something like:
char *find = ....
int len = strlen(find);
char *end = (buf + l) - len;
for(char *p = buf; p < end; p++) {
if(strncmp(p, find, len) == 0) {
// you have found ascii string in buf
}
}
If it's not an ascii string you are looking for use memcmp
() instead of strncmp
.