Advertisement
Guest User

Untitled

a guest
May 26th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. char *DeleteEmpty (char *s)
  5. {
  6. int i=0,j=0;
  7. char *str2=(char*)malloc(strlen(s)+1);
  8. while(s!='\0');
  9. {
  10. if(s[i]!=' ')
  11. {
  12. str2[j++]=s[i++];
  13. }
  14. i++;
  15. }
  16. str2[j]='\0';
  17. return str2;
  18. free (str2);
  19. }
  20. int main()
  21. {
  22. char *str1="My dear friend";
  23. printf("str1為:%s\n",str1);
  24. printf("str2為:%s\n",DeleteEmpty(str1));
  25. return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement