1. #include
  2. #include
  3.  
  4. #define SIZE 100
  5.  
  6. int str_modify(char* str, char* new_str);
  7. int str_len(char* str);
  8.  
  9. int main() {
  10.     char str[20] = "12 *3 + 4/5 + 6 789";  
  11.     char new_str[SIZE] = { 0, };
  12.  
  13.  
  14.     printf("문자열에서 공백 제거한 문자열 길이 : %d\n", str_modify(str, new_str));
  15.     printf("new_str : %s ", new_str);
  16.  
  17.     return 0;
  18.  
  19. }
  20.  
  21.  
  22.  
  23. int str_len(char* str) {
  24.     int len = 0;
  25.     while (*str != NULL) {
  26.         str++;
  27.         len++;
  28.     }
  29.     return len;
  30. }
  31.  
  32. int str_modify(char* str, char* new_str) {
  33.     int len = str_len(str);
  34.     char *temp = str;              //소스배열 시작주소
  35.  
  36.     for (;*str != NULL;str++) {
  37.         if (*str == ' ') {         //공백 찾으면
  38.             *(str++) = NULL;       //널로 바꿔 주고
  39.             strcat(new_str, temp); //새로운 배열에 붙여넣기
  40.             temp = str;            //다음 시작지점 주소로 옮기기
  41.         }
  42.     }
  43.  
  44.     strcat(new_str, temp);
  45.    
  46.     return str_len(new_str);
  47. }

문자열 포인터 선언하면 값 못바꿔서 에러가 나는거임 특별히 코드도 짜줬음 ㅇㅅㅇ