2015-02-04 4 views
1

이 코드를 실행할 때마다 컴파일이 잘되지만 콘솔에 표시가 없습니다. 연결된 목록의 모든 숫자를 인쇄해야하며 문제가 무엇인지 이해하지 못합니다.프로그램이 아무것도 표시하지 않음

#define RAND_MAX 100 

struct num_node{ 
    int num; 
    struct num_node* next; 
}; 


struct num_node *create(struct num_node *list, int num); 
void print_nums(struct num_node *list); 

기능 소스

#include <stdio.h> 
#include <stdlib.h> 
#include "functions.h" 

struct num_node *create(struct num_node *list, int x){ 
    struct num_node *current; 

    if (list == NULL){ 
     list = (struct num_node*)malloc(sizeof(struct num_node)); 
     list->num = x; 
     list->next = NULL; 
     return(list); 
    } 
    else{ 
     current = (struct num_node *)malloc(sizeof(struct num_node)); 
     current->num = x; 
     current->next = list; 
     return(current); 
    } 
} 

void print_nums(struct num_node *list) { 

    struct num_node *current; 
    for (current = list; current != NULL; current = current->next) 
     printf("%d\n", current->num); 

} 

메인 헤더 파일

#include <stdio.h> 
#include <stdlib.h> 
#include <time.h> 

#include "functions.h" 

int main(){ 
    struct num_node *head = NULL; 

    srand(time(NULL)); 

     for (int i = 1; i <= 25; i++){ 
      int x = rand() % 100; 
      create(head, x); 
     } 

     print_nums(head); 

} 
+0

몇 분은 모두이 질문에 대한 필요성을 피할 수 있었을 것이다. –

답변

3

당신은 결코 값 리턴을 사용하지 편집자 : create.

headprint_nums으로 전달할 때 여전히 NULL입니다.

이 있어야한다 : 디버거에서 head = create(head, x);

관련 문제