<p style="margin:0px;padding:0px;font-family:'Helvetica-Light', 'HelveticaNeue-Light', 'Helvetica Neue Light', '나눔고딕', nanumgothic, AppleSDGothicNeo, 'malgun gothic', '맑은 고딕', sans-serif;font-size:14px;"><span>#include <stdio.h></span></p> <p style="margin:0px;padding:0px;font-family:'Helvetica-Light', 'HelveticaNeue-Light', 'Helvetica Neue Light', '나눔고딕', nanumgothic, AppleSDGothicNeo, 'malgun gothic', '맑은 고딕', sans-serif;font-size:14px;"> </p> <p style="margin:0px;padding:0px;font-family:'Helvetica-Light', 'HelveticaNeue-Light', 'Helvetica Neue Light', '나눔고딕', nanumgothic, AppleSDGothicNeo, 'malgun gothic', '맑은 고딕', sans-serif;font-size:14px;">int main()</p> <p style="margin:0px;padding:0px;font-family:'Helvetica-Light', 'HelveticaNeue-Light', 'Helvetica Neue Light', '나눔고딕', nanumgothic, AppleSDGothicNeo, 'malgun gothic', '맑은 고딕', sans-serif;font-size:14px;"><span>{</span></p> <p style="margin:0px;padding:0px;font-family:'Helvetica-Light', 'HelveticaNeue-Light', 'Helvetica Neue Light', '나눔고딕', nanumgothic, AppleSDGothicNeo, 'malgun gothic', '맑은 고딕', sans-serif;font-size:14px;"><span> char temp[100]; // </span><span style="font-weight:600;font-family:'AppleSDGothicNeo-Bold';">문자열을 입력 받기 위한 충분한 크기의 문자 배열을 선언한다.</span></p> <p style="margin:0px;padding:0px;font-family:'Helvetica-Light', 'HelveticaNeue-Light', 'Helvetica Neue Light', '나눔고딕', nanumgothic, AppleSDGothicNeo, 'malgun gothic', '맑은 고딕', sans-serif;font-size:14px;"><span> char *str[5]; // 포인터배열</span></p> <p style="margin:0px;padding:0px;font-family:'Helvetica-Light', 'HelveticaNeue-Light', 'Helvetica Neue Light', '나눔고딕', nanumgothic, AppleSDGothicNeo, 'malgun gothic', '맑은 고딕', sans-serif;font-size:14px;"><span> </span></p> <p style="margin:0px;padding:0px;font-family:'Helvetica-Light', 'HelveticaNeue-Light', 'Helvetica Neue Light', '나눔고딕', nanumgothic, AppleSDGothicNeo, 'malgun gothic', '맑은 고딕', sans-serif;font-size:14px;"><span> for(int i=0; i<5 i++)</span></p> <p style="margin:0px;padding:0px;font-family:'Helvetica-Light', 'HelveticaNeue-Light', 'Helvetica Neue Light', '나눔고딕', nanumgothic, AppleSDGothicNeo, 'malgun gothic', '맑은 고딕', sans-serif;font-size:14px;"><span> {</span></p> <p style="margin:0px;padding:0px;font-family:'Helvetica-Light', 'HelveticaNeue-Light', 'Helvetica Neue Light', '나눔고딕', nanumgothic, AppleSDGothicNeo, 'malgun gothic', '맑은 고딕', sans-serif;font-size:14px;"><span> printf("문자열을 입력해 주세요 : ");</span></p> <p style="margin:0px;padding:0px;font-family:'Helvetica-Light', 'HelveticaNeue-Light', 'Helvetica Neue Light', '나눔고딕', nanumgothic, AppleSDGothicNeo, 'malgun gothic', '맑은 고딕', sans-serif;font-size:14px;"><span> gets(temp); // </span><span style="font-weight:600;font-family:'AppleSDGothicNeo-Bold';">문자열을 입력 받는다.</span></p> <p style="margin:0px;padding:0px;font-family:'Helvetica-Light', 'HelveticaNeue-Light', 'Helvetica Neue Light', '나눔고딕', nanumgothic, AppleSDGothicNeo, 'malgun gothic', '맑은 고딕', sans-serif;font-size:14px;"><span> str = (char *)malloc(strlen(temp) + 1); // </span><span style="font-weight:600;font-family:'AppleSDGothicNeo-Bold';">문자열의 길이를 계산하여 크기에 맞게 기억공간을 동적할당</span></p> <p style="margin:0px;padding:0px;font-family:'Helvetica-Light', 'HelveticaNeue-Light', 'Helvetica Neue Light', '나눔고딕', nanumgothic, AppleSDGothicNeo, 'malgun gothic', '맑은 고딕', sans-serif;font-size:14px;"><span> strcpy(str[i], temp); // </span><span style="font-weight:600;font-family:'AppleSDGothicNeo-Bold';">문자열을 복사한다.</span></p> <p style="margin:0px;padding:0px;font-family:'Helvetica-Light', 'HelveticaNeue-Light', 'Helvetica Neue Light', '나눔고딕', nanumgothic, AppleSDGothicNeo, 'malgun gothic', '맑은 고딕', sans-serif;font-size:14px;"><span> }</span></p> <p style="margin:0px;padding:0px;font-family:'Helvetica-Light', 'HelveticaNeue-Light', 'Helvetica Neue Light', '나눔고딕', nanumgothic, AppleSDGothicNeo, 'malgun gothic', '맑은 고딕', sans-serif;font-size:14px;"><span> </span></p> <p style="margin:0px;padding:0px;font-family:'Helvetica-Light', 'HelveticaNeue-Light', 'Helvetica Neue Light', '나눔고딕', nanumgothic, AppleSDGothicNeo, 'malgun gothic', '맑은 고딕', sans-serif;font-size:14px;"><span> for(i=0; i<5; i++)</span></p> <p style="margin:0px;padding:0px;font-family:'Helvetica-Light', 'HelveticaNeue-Light', 'Helvetica Neue Light', '나눔고딕', nanumgothic, AppleSDGothicNeo, 'malgun gothic', '맑은 고딕', sans-serif;font-size:14px;"><span> {</span></p> <p style="margin:0px;padding:0px;font-family:'Helvetica-Light', 'HelveticaNeue-Light', 'Helvetica Neue Light', '나눔고딕', nanumgothic, AppleSDGothicNeo, 'malgun gothic', '맑은 고딕', sans-serif;font-size:14px;"><span> printf("%s\n", str[i]);</span></p> <p style="margin:0px;padding:0px;font-family:'Helvetica-Light', 'HelveticaNeue-Light', 'Helvetica Neue Light', '나눔고딕', nanumgothic, AppleSDGothicNeo, 'malgun gothic', '맑은 고딕', sans-serif;font-size:14px;"><span> }</span></p> <p style="margin:0px;padding:0px;font-family:'Helvetica-Light', 'HelveticaNeue-Light', 'Helvetica Neue Light', '나눔고딕', nanumgothic, AppleSDGothicNeo, 'malgun gothic', '맑은 고딕', sans-serif;font-size:14px;"><span> </span></p> <p style="margin:0px;padding:0px;font-family:'Helvetica-Light', 'HelveticaNeue-Light', 'Helvetica Neue Light', '나눔고딕', nanumgothic, AppleSDGothicNeo, 'malgun gothic', '맑은 고딕', sans-serif;font-size:14px;"> </p> <p style="margin:0px;padding:0px;font-family:'Helvetica-Light', 'HelveticaNeue-Light', 'Helvetica Neue Light', '나눔고딕', nanumgothic, AppleSDGothicNeo, 'malgun gothic', '맑은 고딕', sans-serif;font-size:14px;"><span> for(i=0; i<5; i++)</span></p> <p style="margin:0px;padding:0px;font-family:'Helvetica-Light', 'HelveticaNeue-Light', 'Helvetica Neue Light', '나눔고딕', nanumgothic, AppleSDGothicNeo, 'malgun gothic', '맑은 고딕', sans-serif;font-size:14px;"><span> {</span></p> <p style="margin:0px;padding:0px;font-family:'Helvetica-Light', 'HelveticaNeue-Light', 'Helvetica Neue Light', '나눔고딕', nanumgothic, AppleSDGothicNeo, 'malgun gothic', '맑은 고딕', sans-serif;font-size:14px;"><span> free(str[i]); //할당한 메모리 영역 해제</span></p> <p style="margin:0px;padding:0px;font-family:'Helvetica-Light', 'HelveticaNeue-Light', 'Helvetica Neue Light', '나눔고딕', nanumgothic, AppleSDGothicNeo, 'malgun gothic', '맑은 고딕', sans-serif;font-size:14px;"><span> }</span></p> <p style="margin:0px;padding:0px;font-family:'Helvetica-Light', 'HelveticaNeue-Light', 'Helvetica Neue Light', '나눔고딕', nanumgothic, AppleSDGothicNeo, 'malgun gothic', '맑은 고딕', sans-serif;font-size:14px;"><span> </span></p> <p style="margin:0px;padding:0px;font-family:'Helvetica-Light', 'HelveticaNeue-Light', 'Helvetica Neue Light', '나눔고딕', nanumgothic, AppleSDGothicNeo, 'malgun gothic', '맑은 고딕', sans-serif;font-size:14px;"><span> return 0;</span></p> <p style="margin:0px;padding:0px;font-family:'Helvetica-Light', 'HelveticaNeue-Light', 'Helvetica Neue Light', '나눔고딕', nanumgothic, AppleSDGothicNeo, 'malgun gothic', '맑은 고딕', sans-serif;font-size:14px;"><span><br></span></p> <p style="margin:0px;padding:0px;font-family:'Helvetica-Light', 'HelveticaNeue-Light', 'Helvetica Neue Light', '나눔고딕', nanumgothic, AppleSDGothicNeo, 'malgun gothic', '맑은 고딕', sans-serif;font-size:14px;"><span>}</span></p> <p style="margin:0px;padding:0px;font-family:'Helvetica-Light', 'HelveticaNeue-Light', 'Helvetica Neue Light', '나눔고딕', nanumgothic, AppleSDGothicNeo, 'malgun gothic', '맑은 고딕', sans-serif;font-size:14px;"><span>위는 제가 작성한 것이 아니라, 책이나 인터넷에서 사용하는 동적 char 할당을 보면서, 느끼는 사항입니다. </span></p> <p style="margin:0px;padding:0px;font-family:'Helvetica-Light', 'HelveticaNeue-Light', 'Helvetica Neue Light', '나눔고딕', nanumgothic, AppleSDGothicNeo, 'malgun gothic', '맑은 고딕', sans-serif;font-size:14px;"><span>계속 보면서 느끼는 것이지만, C는 동적인 문자열쓰기가 아닌 것 같다고 느끼는 중입니다. </span></p> <p style="margin:0px;padding:0px;font-family:'Helvetica-Light', 'HelveticaNeue-Light', 'Helvetica Neue Light', '나눔고딕', nanumgothic, AppleSDGothicNeo, 'malgun gothic', '맑은 고딕', sans-serif;font-size:14px;"><span>배열로 메모리 공간 겁나크게 할당해 놓고 다시 포인터로 옮겨도 배열의 메모리는 살아있는데, </span></p> <p style="margin:0px;padding:0px;font-family:'Helvetica-Light', 'HelveticaNeue-Light', 'Helvetica Neue Light', '나눔고딕', nanumgothic, AppleSDGothicNeo, 'malgun gothic', '맑은 고딕', sans-serif;font-size:14px;"><span>그럼 포인터를 사용할 이유가 없지 않나요? 처음부터 그냥 배열(걍 배열이던, 2중배열이던 ) 겁나크게 놓고 사용하면 될 것 같은데요. </span></p> <p style="margin:0px;padding:0px;font-family:'Helvetica-Light', 'HelveticaNeue-Light', 'Helvetica Neue Light', '나눔고딕', nanumgothic, AppleSDGothicNeo, 'malgun gothic', '맑은 고딕', sans-serif;font-size:14px;">구조는 이해하지만, 방법이 없나 하는 생각을 해봅니다. 역시... 안되겠지요. 걍 중얼거려봅니다. </p> <p style="margin:0px;padding:0px;font-family:'Helvetica-Light', 'HelveticaNeue-Light', 'Helvetica Neue Light', '나눔고딕', nanumgothic, AppleSDGothicNeo, 'malgun gothic', '맑은 고딕', sans-serif;font-size:14px;"><br></p>
댓글 분란 또는 분쟁 때문에 전체 댓글이 블라인드 처리되었습니다.