SHOW:
|
|
- or go back to the newest paste.
| 1 | /* Search a word ( example : book ) from a sentence and show nth number where the word is in the sentence */ | |
| 2 | ||
| 3 | #include<stdio.h> | |
| 4 | #include<stdlib.h> | |
| 5 | #include<string.h> | |
| 6 | ||
| 7 | int main(void) | |
| 8 | {
| |
| 9 | char str[80]; | |
| 10 | gets(str); | |
| 11 | int length=strlen(str); | |
| 12 | int i; | |
| 13 | int counter=1; | |
| 14 | for(i=0;i<length;i++) | |
| 15 | {
| |
| 16 | if(str[i]==' ') | |
| 17 | {
| |
| 18 | counter++; | |
| 19 | } | |
| 20 | ||
| 21 | if(str[i]=='b'&&str[i+1]=='o'&&str[i+2]=='o'&&str[i+3]=='k') | |
| 22 | {
| |
| 23 | printf("found\n");
| |
| 24 | printf("%d \n",counter);
| |
| 25 | return 0; | |
| 26 | } | |
| 27 | } | |
| 28 | if(counter==0) | |
| 29 | {
| |
| 30 | printf("not found \n");
| |
| 31 | } | |
| 32 | return 0; | |
| 33 | } |