Take the 2-minute tour ×  How can one compare a string from the
middle (or some other point but not the start) to another
string? like i have a string str1[]="I am genius"; now if i want
to find a word in it how should i compare it with the word? for
example the word is am. Here is what i did.Its a bit stupid but
works perfectly :D     void print( char string[]);   int  main()
int i;   char string1[20];   printf("Enter a string:");   return
0; void print(char string[])     int i,word=1,sum=0,x;
for(i=0;    ;i++)      if(string[i]==' ')     }/* if ends */
{    // program sai kaam karnay k liye ye code yahan bhi paste
hona chahyey     }/* for ends*/  share|improve this question
Please note that finding a word inside a string is better not
performed with string comparisons, but rather with finite state
machines (en.wikipedia.org/wiki/… ) –  Alexandre C. Jul 15 '10
at 11:05 add comment  6 Answers  up vote 4 down vote accepted
Use strncmp():  strncmp( whereToFind + offsetToStartAt,
patternToFind, patt