rahulb5

delete a word from a sentence

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