Guest User

Untitled

a guest
Apr 24th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.38 KB | None | 0 0
  1. const int size=80;
  2. char str[size];
  3. int index=0;
  4. char ch=0,lastChar=0;
  5. printf("enter your string(80 chars)\n");
  6. for(int i=0;i<(size-1);i++)/*room for our null byte*/
  7. {
  8.     ch=getchar();
  9.     if(ch == EOF || ch == '\n')
  10.         break;
  11.     if(ch == ' ' && lastChar== ' ')
  12.         continue;
  13.     lastChar = ch;
  14.     str[index] = ch;
  15.     index++;
  16. }
  17. /*fix null byte*/
  18. str[index] = '\0';
  19. printf("%s\n",str);
Add Comment
Please, Sign In to add comment