- #include
- #include
- #define SIZE 100
- int str_modify(char* str, char* new_str);
- int str_len(char* str);
- int main() {
- char str[20] = "12 *3 + 4/5 + 6 789";
- char new_str[SIZE] = { 0, };
- printf("문자열에서 공백 제거한 문자열 길이 : %d\n", str_modify(str, new_str));
- printf("new_str : %s ", new_str);
- return 0;
- }
- int str_len(char* str) {
- int len = 0;
- while (*str != NULL) {
- str++;
- len++;
- }
- return len;
- }
- int str_modify(char* str, char* new_str) {
- int len = str_len(str);
- char *temp = str; //소스배열 시작주소
- for (;*str != NULL;str++) {
- if (*str == ' ') { //공백 찾으면
- *(str++) = NULL; //널로 바꿔 주고
- strcat(new_str, temp); //새로운 배열에 붙여넣기
- temp = str; //다음 시작지점 주소로 옮기기
- }
- }
- strcat(new_str, temp);
- return str_len(new_str);
- }
문자열 포인터 선언하면 값 못바꿔서 에러가 나는거임 특별히 코드도 짜줬음 ㅇㅅㅇ
해당 댓글은 삭제되었습니다.
돈 줘 ㅇㅅㅇ
장난이야 열공해 ㅇㅅㅇ