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
找到您的代碼中的匹配大括號... – Floris