gpt4 book ai didi

c - 为什么我的代码不起作用?链接列表

转载 作者:行者123 更新时间:2023-11-30 20:56:41 25 4
gpt4 key购买 nike

q2 to demonstrate linked list operations:insertion,display & deletion//

the compiler code blocks is telling the two error at lines

73 and 83 which i have marked expected ; before'{' token

and expected declaration or statement at the end of the input*/

but it is also telling that in function create:these two error are there !how is that possible when it is referring them to be in the main()

#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

最佳答案

关于第一个预期;在'{' token 错误之前,而不是

main()

您应该使用完整签名

int main(int argc, char **argv)

对于第二个错误,您应该首先正确缩进代码。

关于c - 为什么我的代码不起作用?链接列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22132048/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com