fork(1) download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int group(char ch)
  5. {
  6. return isalpha(ch) ? 0 : isspace(ch) ? 1 : 2;
  7. }
  8.  
  9. void word(char **r, char *s, int g)
  10. {
  11. for (; *s && group(*s) == g; ++s)
  12. *((*r)++) = *s;
  13. }
  14.  
  15. int main(void)
  16. {
  17. char str[256], res[256], *s, *r;
  18. int next;
  19.  
  20. while (gets(str))
  21. {
  22. r = res;
  23.  
  24. for (next=group(s=str+strlen(str)-1); ; --s)
  25. if (s == str)
  26. {
  27. word(&r, s, group(*s));
  28. break;
  29. }
  30. else if (group(*s) != next)
  31. {
  32. word(&r, s+1, next);
  33. next = group(*s);
  34. }
  35.  
  36. *r = 0;
  37.  
  38. puts(res);
  39. }
  40.  
  41. return 0;
  42. }
  43.  
Success #stdin #stdout 0s 2172KB
stdin
My name is qwe.
isalpha can return 1024 :(
multyspace  goes   here as 2-3-1-1
stdout
.qwe is name My
:( 1024 return can isalpha
2-3-1-1 as here   goes  multyspace