이것때문에 3일을 해메고 있습니다. 도와주세요 ㅜㅜ
나려
질문 제목 : 이것때문에 3일을 해메고 있습니다. 도와주세요 ㅜㅜ
질문 요약 :동적 할당된 포인터가호출 함수로 복귀시NULL(0)이 되는 이유 좀...
질문 내용 :
Node *Create_node_match(List **Alias_list, Node ****node_match, const char *name_str, const int *node_match_index)
{
int i;
Node *current_node;
// 메모리 할당
*node_match=(Node***)malloc(sizeof(Node**)*(*node_match_index+1));
*node_match[*node_match_index]=(Node**)malloc(sizeof(Node*)*2);
// name을 리스트에 저장
*node_match[*node_match_index][0]=Deque_add_Node(Alias_list[0], name_str, 0, NULL);
return NULL;
}
void Store_alias_str(List **Alias_list, Command *Cmd, Node ****node_match, int *node_match_index, char *name_str, char *value_str, const int alias_index)
{
int i, j, len;
Node *current_node;
Create_node_match(Alias_list, node_match, name_str, node_match_index);
// value를 리스트에 저장
*node_match[*node_match_index][1]=Deque_add_Node(Alias_list[1], &value_str[1], 0, NULL);
current_node=(*node_match[*node_match_index][1]);
++(*node_match_index);
printf(name : %x\n, *node_match[*node_match_index-1][0]);
printf(value : %x\n, *node_match[*node_match_index-1][1]);
}
Alias_Command *Sh_alias_unalias(Command *Cmd)
{
static int node_match_index=0; // 가장 마지막 인덱스 값보다 항상 1이 크다(갯수 개념)
static Node ***node_match=NULL;
static List **Alias_list=NULL;
// name과 value 값을 리스트에 저장
Store_alias_str(Alias_list, Cmd, &node_match, &node_match_index, name_str, value_str, alias_index);
printf(name : %x\n, node_match[node_match_index-1][0]);
printf(value : %x\n, node_match[node_match_index-1][1]);
}
코드가 좀 길어서 관련된 부분만 최대한 축약했습니다
함수 호출 순서는 Sh_alias_unalias - Store_alias_str - Create_node_match 순서로 호출됩니다
위의 코드를 실행하면 결과가 다음과 같이 나옵니다.name : 9f73de8
value : 9f73e08
name : 9f73de8
value : 0여기서 두번째로 출력되는 value 가 왜 0이 되는지 도저히 모르겠네요(3일을 해매고 있어요 ㅠㅠ)
고수님들 도와주시면 감사드리겠습니다 ㅜㅜ
-
수리 2024-04-06
수다님 감사합니다~ 덕분에 해결했어요 ㅜㅜ 댓글 달아주신 모든 분들께 정말 감사드립니다~^^
-
올리브 2024-04-06
printf(\value : %x\\n\
-
푸른잎 2024-04-06
알아보기 힘들네요 전체소스라도 올려주시면 한줄 돌리서라도 머가 틀렸는지 알수 있겠지만 이렇게 올려주시면 찾기도 힘들어요 ㄷㄷ
-
패틱 2024-04-06
*가 4개나 붙는 경우도 있군요... 코드를 알아보기가 아주 힘드네요.
typedef를 통하여 포인터 변수 등의 이름을 재정의해서 가독성을 높이는 작업이 먼저 필요할 것 같습니다.