fork download
  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[i] !='\0') {
  9. if (s[i] !=' ') {
  10. str2[j++]=s[i++];
  11. } else {
  12. i++;
  13. }
  14. }
  15. str2[j]='\0';
  16. return str2;
  17. }
  18. int main() {
  19. char *str1="My dear friend";
  20. printf("str1為:%s\n",str1);
  21. printf("str2為:%s\n",DeleteEmpty(str1));
  22. return 0;
  23. }
Success #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
str1為:My dear friend
str2為:Mydearfriend