Advertisement
sellmmaahh

string-whitespace

Aug 8th, 2015
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.99 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4.  
  5. char* whitespace (char* s) {
  6.     int i=0,j=0;
  7.     char *poc=s;
  8.     while (*(s+i)!='\0') {
  9.             if(*(s+i)==' ' || *(s+i)=='\t' || *(s+i)=='\n')
  10.                { *(s+i)=' ';
  11.                  j=i+1;
  12.                  while (*(s+j)==' ' || *(s+j)=='\t' || *(s+j)=='\n') j++;
  13.                  if (j!=i+1) {
  14.                         while (*(s+1+i)!='\0') {
  15.                                 *(s+i+1)=*(s+j);
  16.                                 s++;
  17.                         }
  18.                         *(s+i)='\0';
  19.                  } s=poc;
  20.                }
  21.                i++;
  22.     }
  23.  
  24.     return poc;
  25.     }
  26.  
  27. int main () {
  28.     printf("Unesite jednu recenicu sa maks. 100 znakova: ");
  29.     char recenica[100],c;
  30.     int i=0,n;
  31.     do {
  32.             c=getchar();
  33.             recenica[i]=c;
  34.             i++;
  35.     } while (c!='\n' && i<100);
  36.     recenica[i-1]='\0';
  37.  
  38.     printf("\nNova recenica glasi: %s",whitespace(recenica));
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement