2012-12-06 24 views
-1

我有一個我的鏈接列表顯示功能的問題。該功能如下。問題與顯示功能

我只是在switch語句之一中調用函數。但沒有任何顯示。請幫我弄清楚我錯在哪裏。

代碼:

void display() 
{ 
    data *cur_point; 

    cur_point = head;  

    if(cur_point = NULL) 
    { 
     printf("The list is empty"); 
    } 
    else 
    { 
     while(cur_point != NULL) 
     { 
      printf("Name : %s \n Contact Number : %d \n",cur_point->name,cur_point->telno); 
      cur_point = cur_point -> nextp; 
     } 
    } 
} 
+0

請編譯你的程序時使用最大編譯器警告並查看編譯器警告並嘗試修復它們,它們可以幫助你找出像這樣的錯誤 –

回答

2

更改此:

if(cur_point = NULL) 

要:

if(cur_point == NULL) 

瞧! :)(澄清:你在你的代碼中將cur_point設置爲NULL,而不是檢查它是否爲NULL

3

如果你看到這樣的事情,應該立即引起恐慌:

if(cur_point = NULL) 

=受讓人,==會檢查。