rahulb5

find a word in asentencce

Aug 27th, 2014
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. #include<conio.h>
  2. #include<iostream.h>
  3. #include<stdio.h>
  4. #include<string.h>
  5. void main ()
  6. {
  7. clrscr();
  8. char a[100] , b[10],c[10];
  9. int counter = 0;
  10. cout<<"please enter a string : ";
  11. gets(a);
  12. cout<<"please enter a word to look for : ";
  13. gets(b);
  14. for(int i = 0 ; i<strlen(a);i++){
  15. for(int j = 0 ; a[i]!=' ' && a[i]!='\0' ; i++,j++)
  16. c[j] = a[i];
  17. c[j] ='\0';
  18. if(strcmp(c,b)==0)
  19. counter++;
  20. }
  21. cout<<endl<<"the number of times the is "<<counter;
  22. getch();
  23. }
Advertisement
Add Comment
Please, Sign In to add comment