Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. char* newString (char* str)
  6. {
  7. int j = 0;
  8. int i;
  9. int len = strlen(str);
  10. char *res = malloc(100);
  11. for (i = 0; i < len; i ++) {
  12. if (str[i] == ' ') {
  13. if (j == 0)
  14. continue;
  15. if (i + 1 < len && str[i + 1] == ' ')
  16. continue;
  17. }
  18. res[j] = str[i];
  19. j++;
  20. }
  21. return res;
  22. }
  23.  
  24. int main()
  25. {
  26. char *start = malloc(100);
  27. gets(start);
  28. printf("%s", newString(start));
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement