It all depends on how the file is formatted and how deeply you want to scan. If the int is a word of its own and not part of a larger word, you can just read words and check for the int:
#include <stdbool.h>
#include <stdio.h>
bool is_int(char const* s, int* value)
{
// Fill in this function. strtol() is a good start for testing for int.
}
int main(void)
{
FILE* fp = fopen("file", "r");
if (fp)
{
char word[BUFSIZ];
int needle = /* The int being searched */;
while (fscanf(fp, "%s", word) == 1)
{
int value;
if (is_int(word, &value) && value == needle)
{
puts("FOUND");
break;
}
}
fclose(fp);
}
return 0;
}
deceptikon
Challenge Accepted
3,426 posts since Jan 2012
Reputation Points: 822
Solved Threads: 473
Skill Endorsements: 56