이것때문에 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를 통하여 포인터 변수 등의 이름을 재정의해서 가독성을 높이는 작업이 먼저 필요할 것 같습니다.
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2653584 | 16진수 변환 관련 질문 드립니다. | 매미꽃 | 2024-05-03 |
2653557 | 한글 완성형과 조합형의 전환 | 해지개 | 2024-05-02 |
2653506 | void형 포인터 이해안가요 ㅠㅠ (2) | 뭘봐요 | 2024-05-02 |
2653482 | 패턴매칭에 대한 질문하나 올립니다 | 미투리 | 2024-05-02 |
2653452 | main 함수 매개변수 문의드립니다. (2) | 딥레드 | 2024-05-01 |
2653425 | 간단한 포인터 설명좀 해주세요 ㅠㅠㅠ | 차분나래 | 2024-05-01 |
2653400 | 플로우 차트 작성 질문입니다. (2) | 아인 | 2024-05-01 |
2653370 | c언어 해석 부탁드립니다 ㅠ | 악당 | 2024-05-01 |
2653345 | 분수의 덧셈 질문이요 | 하늘 | 2024-04-30 |
2653313 | //정수 n을 입력받아 1부터 n까지의 합을 구하는 프로그램// (6) | 거북이 | 2024-04-30 |
2653284 | 알파벳 변수 관련(배열에서) | 나슬 | 2024-04-30 |
2653260 | C언어 scanf인데.. | 찬누리 | 2024-04-30 |
2653230 | 한글로 해석부탁드립니다. (1) | BlackCat | 2024-04-29 |
2653142 | 질문드립니다.. 부탁드립니다.. | 머슴밥 | 2024-04-29 |
2653119 | cmd창[도스창, 콘솔창]에 한글이 출력이 안되요. (2) | By은지 | 2024-04-28 |
2653096 | C언어와 C++, 베이직C++의 차이 (1) | 두동 | 2024-04-28 |
2653014 | 전기 분야에서는 C언어가 어떤, 어느 용도로 쓰이나요? (7) | 처녀자리 | 2024-04-27 |
2652986 | c언어 프로그램~~ (5) | 가장 | 2024-04-27 |
2652907 | mciSendString 함수 플레이 시간, (1) | 해나 | 2024-04-26 |
2652880 | 배열입력을 묻고 싶습니다 (3) | 사에 | 2024-04-26 |