Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Search a word ( example : book ) from a sentence and show nth number where the word is in the sentence */
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- int main(void)
- {
- char str[80];
- gets(str);
- int length=strlen(str);
- int i;
- int counter=1;
- for(i=0;i<length;i++)
- {
- if(str[i]==' ')
- {
- counter++;
- }
- if(str[i]=='b'&&str[i+1]=='o'&&str[i+2]=='o'&&str[i+3]=='k')
- {
- printf("found\n");
- printf("%d \n",counter);
- return 0;
- }
- }
- if(counter==0)
- {
- printf("not found \n");
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment