rahulb5

delete extra spaces

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