fork download
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5.  
  6. void removeWords(char * buf)
  7. {
  8. char * s = buf;
  9. while(ispunct(*s) || isblank(*s)) ++s;
  10. while(isalnum(*s)) ++s;
  11. while(ispunct(*s) || isblank(*s)) ++s;
  12. memmove(buf,s,strlen(s)+1);
  13.  
  14. s = buf + strlen(buf) - 1;
  15. while(ispunct(*s) || isblank(*s) || *s=='\n') --s;
  16. while(isalnum(*s)) --s;
  17. *s++ = '\n';
  18. *s = 0;
  19. }
  20.  
  21. int main()
  22. {
  23. #define MAXLEN 512
  24. char buf[MAXLEN];
  25. for(int no = 1; fgets(buf,MAXLEN,stdin); ++no)
  26. {
  27. if (no%2==0) removeWords(buf);
  28. printf("%3d: %s",no,buf);
  29. }
  30. }
  31.  
Success #stdin #stdout 0s 4712KB
stdin
first string hello
second string world!
third string Bye-bye,
fourth string cruel world...
stdout
  1: first string hello
  2: string
  3: third string Bye-bye,
  4: string cruel