Wednesday 15 June 2011

loops - C :How to compare two strings and find a word i need? -



loops - C :How to compare two strings and find a word i need? -

its not complete, in doesnt print anything

char *fruit[] = {"rasberry", "cherry"}; char *veg[] = {"salad", "tomato"}; char word; printf("print veg or fruit \n"); scanf("%s", &word); (int = 0; < strcmp(fruit, veg ); i++) { if (word == fruit[i]) printf("its fruit!"); }

how compare it?

ok after bit more clarification needed, seek this:

char *fruit[] = {"rasberry", "cherry"}; char *veg[] = {"salad", "tomato"}; char word[100]={0}; printf("print veg or fruit \n"); scanf("%s", word); // check fruit (int = 0; < 2; i++) { if (strcmp(word,fruit[i])==0) { printf("its fruit \n"); } } // check veg (int = 0; < 2; i++) { if (strcmp(word,veg[i])==0) { printf("its veg \n"); } }

c loops compare strcmp

No comments:

Post a Comment