2014-03-02 68 views
-3

Q2證明鏈表操作:?插入,顯示&刪除//爲什麼不是我的代碼工作的鏈接列表

編譯器代碼塊告訴在行兩個錯誤

73我已標明預期的83個;之前,在輸入的結束「{」令牌

和預期的聲明或聲明*/

,但它也告訴在函數創建: 這兩個錯誤在那裏怎麼可能當它是參照他們在主()

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

struct list 
{ 
    int a; 
    char name[20]; 
    int roll; 
    struct list *next; 
}; 

struct list *create(struct list *ptr) 
{ 
    int v,n; 
    printf("\nenter the value of the inputs"); 
    scanf("%d",&n); 
    struct list *temp; 
    printf("\ndo u want to continue(y/n)"); 
    scanf("%d",&v); 
    while(1) 
    { 
     if(v=='y') 
     { 
      ptr=(struct list*)malloc(sizeof(struct list)); 
      printf("\nenter the roll number of the student"); 
      scanf("%d",&ptr->roll); 
      printf("\nenter the name of the student"); 
      gets(ptr->name); 
      printf("\nenter the marks of the student"); 
      scanf("%d",&ptr->a); 
      ptr->next=NULL; 
     } 
     else 
      if(v=='n') 
      { 
       break; 
      } 
     return(ptr); 
    } 
} 
void display(struct list *ptr) 
{ 
    struct list *temp; 
    temp=ptr; 
    while(temp!=NULL) 
    { 
     printf("\nthe roll number of the student is%d",temp->roll); 
     printf("\nthe name of the student is%d",temp->name); 
     printf("\nthe marks of the student is%d",temp->a); 
     temp=temp->next; 
    } 
} 

void del(struct list *ptr,int c) 
{ 
    struct list *temp; 
    struct list *gtemp; 
    gtemp=temp=ptr; 

    while(temp->roll!=c) 
    { 
     gtemp=temp; 
     temp=temp->next; 
    } 
    gtemp->next=temp->next; 
    free(temp); 
} 
main() 
{ //73 
    struct list *ptr; 
    int c; 
    ptr=NULL; 
    ptr=create(ptr); 
    display(ptr); 
    printf("\nenter the value of roll number"); 
    scanf("%d",&c); 
    del(ptr,c); 
    display(ptr); 
}//83 
+0

找到您的代碼中的匹配大括號... – Floris

回答

1

關於第一expected ; before'{' token錯誤,而不是

main() 

你應該使用完整的簽名

int main(int argc, char **argv) 

第二個錯誤,你首先應該正確縮進代碼。

+0

這是一個答案?第一部分與OP的問題無關,第二部分是請求而不是答案... –

+0

op問題的意思是? – ninja

+0

沒有必要把全部簽名一個'}'需要之前diplay定義 – ninja

1

正確檢查{}組合。你主要在create {}函數中寫入display()函數的區別。所以請正確添加{}對。在display()函數定義之前添加一個關閉'}'以保持縮進 。

printf("\nthe name of the student is%d",temp->name); 

它應該是%s表示字符串。

+0

意味着什麼? – ninja

+0

@ user3371423縮進。代碼必須以格式良好的方式排列。那個時候你可以很容易地發現錯誤,比如這些缺失}。甚至閱讀代碼對其他人也會更容易。 – LearningC

+0

我添加了一個額外的}之前顯示它的工作,但突然編譯器停止n。爲什麼? – ninja

相關問題