<p>/* 일단 소스부터 보시죠 */</p><p><br></p><p>typedef struct test</p><p>{</p><p>int decimal;</p><p><span style="font-size: 10pt; line-height: 1.8;">char check;</span></p><p><span style="font-size: 10pt; line-height: 1.8;">} test;</span></p><p><br></p><p>test* Make (term source[]);</p><p><span style="font-size: 10pt; line-height: 1.8;"><br></span></p><p><span style="font-size: 10pt; line-height: 1.8;">int main (void)</span></p><p><span style="font-size: 10pt; line-height: 1.8;">{</span></p><p><span style="font-size: 10pt; line-height: 1.8;">test a1[100];</span></p><p><span style="font-size: 10pt; line-height: 1.8;">test a2[100][100];</span></p><p><span style="font-size: 10pt; line-height: 1.8;"><br></span></p><p>a2[0] = a1; //중간과정 생략하고 아무튼 a2[0]에 a1을 넣음. </p><p>a2[1] = Make (a2[0]);</p><p><span style="font-size: 10pt; line-height: 1.8;"><br></span></p><p><span style="font-size: 10pt; line-height: 1.8;">return 0;</span></p><p><span style="font-size: 10pt; line-height: 1.8;">}</span></p><p><span style="font-size: 10pt; line-height: 1.8;"><br></span></p><p><span style="font-size: 10pt; line-height: 1.8;">test* Make (term source[])</span></p><p><span style="font-size: 10pt; line-height: 1.8;">{</span></p><p style="margin-left: 2em;"><span style="font-size: 10pt; line-height: 1.8;">test *temp; </span></p><p style="margin-left: 2em;"><span style="font-size: 10pt; line-height: 1.8;">//temp 초기화는 했음.</span></p><p style="margin-left: 2em;"><span style="font-size: 10pt; line-height: 1.8;">source[0].check = '1';</span></p><p style="margin-left: 2em;"><span style="font-size: 10pt; line-height: 1.8;">temp.decimal = 1;</span></p><p style="margin-left: 2em;"><span style="font-size: 10pt; line-height: 1.8;"><br></span></p><p style="margin-left: 2em;"><span style="font-size: 10pt; line-height: 1.8;">return temp;</span></p><p><span style="font-size: 10pt; line-height: 1.8;">}</span></p><p><span style="font-size: 10pt; line-height: 1.8;">/* 여기까지가 소스 */</span></p><p><span style="font-size: 10pt; line-height: 1.8;"><br></span></p><p><span style="font-size: 10pt; line-height: 1.8;">이렇게 하면 함수 Make에서의 source는 a2[0]의 "복사값"이 되는 건 알고 있습니다.</span></p><p><span style="font-size: 10pt; line-height: 1.8;">처음 작성할 때는 복사값만으로 충분했으니까요.</span></p><p><span style="font-size: 10pt; line-height: 1.8;">그런데, " </span><span style="font-size: 10pt; line-height: 1.8;">source[0].check = '1'; " 이 부분을 추가하면서 문제가 생겼습니다.</span></p><p><span style="font-size: 10pt; line-height: 1.8;">일반 자료형 배열이라면 인자를 int source[]로 넘겨받아 함수에서 값을 바꾸면 원본도 바뀌거든요.</span></p><p><span style="font-size: 10pt; line-height: 1.8;"><br></span></p><p><span style="font-size: 10pt; line-height: 1.8;">배열이 아니라 그냥 구조체면 함수 인자에 *source , 함수 내에서는 source->check를 사용하는 것까지는 책을 통해 알았습니다.</span></p><p><span style="font-size: 10pt; line-height: 1.8;"><br></span></p><p><span style="font-size: 10pt; line-height: 1.8;">구조체 배열은 어떻게 처리해야할지 책을 찾아도, 구글링을 해도 시원한 답이 없어서 오유 능력자님들에게 도움을 구합니다.</span></p><p><span style="font-size: 10pt; line-height: 1.8;"><br></span></p>
댓글 분란 또는 분쟁 때문에 전체 댓글이 블라인드 처리되었습니다.