이것때문에 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를 통하여 포인터 변수 등의 이름을 재정의해서 가독성을 높이는 작업이 먼저 필요할 것 같습니다.
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2700368 | if에 관해서 질문이요... | Orange | 2025-07-04 |
2700339 | 이거 결과값이 왜이런건지.. (4) | 그댸와나 | 2025-07-04 |
2700313 | 파일 읽어서 저장하는데 빈파일일 경우 문재가 발생하네요.. (2) | 크나 | 2025-07-03 |
2700287 | 구조체 동적할당 연습을 하는데 오류가 뜹니다...(해결) (3) | 아련나래 | 2025-07-03 |
2700264 | 문자와 숫자 동시에 입력??? | 글고운 | 2025-07-03 |
2700236 | txt파일로만 쓰고 읽게 하려면 어떻게 해야 하나요..?? (8) | 미국녀 | 2025-07-03 |
2700211 | 전위 연산자 (2) | 어른처럼 | 2025-07-02 |
2700183 | C에서 파일이름을 받고, 그 파일의 사이즈를 출력해줘야하는데 내용이 출력이 안되네요 ;ㅅ; | 피스케스 | 2025-07-02 |
2700150 | 꼭좀 도와주세요ㅠㅠㅠ | 호습다 | 2025-07-02 |
2700095 | 연산문제...질문... | 오빤테앵겨 | 2025-07-01 |
2700070 | while문 , 3의배수 출력하는 프로그램좀 짜주세욤. | 횃불 | 2025-07-01 |
2700041 | 초보인데요 ㅎ 배열안에 배열을 집어넣을수 있나요?? | 헛장사 | 2025-07-01 |
2700012 | 배열// (1) | 전갈자리 | 2025-07-01 |
2699895 | 무한루프에 빠집니다.!! 해결좀부탁드려요 (10) | 선아 | 2025-06-30 |
2699842 | 질문을 너무 많이 하네여.....죄송.... (2) | 해님꽃 | 2025-06-29 |
2699816 | 오류 질문입니다.. (1) | 해비치 | 2025-06-29 |
2699763 | 질문입니다 ! 꼭 좀 도와주세요ㅠㅠ (2) | 미라 | 2025-06-28 |
2699555 | c언어 다항식을 입력을 했는데 왜 출력이 안될까요? | 피스케스 | 2025-06-27 |
2699528 | C언어 포인터연산 질문입니다. (3) | 안녕나야 | 2025-06-26 |
2699476 | 끌어올림;;달력 짜봤는데요 이 소스 줄일 수 있나요? - 스샷첨부 (2) | 클라우드 | 2025-06-26 |