Speakmore Speakmore - 1 month ago 14
C Question

Comparing char to string - C

so I've viewed multiple threads here now on this site about comparing my char array to a string or something of that sort with things like

strcmp
and
strstr
however whenever I compiled it, I got the error:

warning: incompatible implicit declaration of built-in function 'strstr' [enabled by default]


and honestly I have no idea what this means. I'm relatively new to C...

So here's my code:

int main(){

FILE * fPointer;
fPointer = fopen("test.txt", "r");

char action[10];
char num[100];
char* s;

while(fscanf(fPointer, "%s", action) != EOF){
s = strstr(action, "JUMP");
if(s != NULL){
puts("Jump");
}else{
puts("Don't Jump");
}
}

fclose(fPointer);

}


I've tried a few other things, but none of them worked out. My text file has a bunch of actions:

JUMP 4
CRUNCH 7
SITUP 8


and other similar things like that. I wanted the while loop to scan for each action, and then compare it to whatever to see if action is = to "jump" etc, etc, and if it is, then scan the number to tell me how many times to do each action.

Can someone help me with this? Thanks so much!

Answer

You haven't included the proper header.

#include <string.h>