strstr whole string match
- by clay
I'm trying to match the whole string and not just part of it. For instance, if the needle is 2, I would like to match just the string 2 and not 20, 02, or 22 or anything related.
I'm using strstr as:
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
FILE *file;
char l[BUFSIZ];
int linenumber = 1;
char term[6] = "2";
file = fopen(argv[1], "r");
if(file != NULL) {
while(fgets(l, sizeof(l), file)){
if(strstr(l, term) != NULL) {
printf("Search Term Found at %d!\n", linenumber);
}
++linenumber;
}
}
else {
perror(argv[1]);
}
fclose(file);
return 0;
}