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



Q2 演示链表操作:插入、显示和删除//

编译器代码块在行中告诉两个错误

73 和 83 我已经标记了预期;在"{"标记之前

以及输入末尾的预期声明或声明*/

但它也告诉在函数中创建:这两个错误是存在的!当它引用它们在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

关于第一个expected ; before'{' token错误,而不是

main()

您应该使用完整签名

int main(int argc, char **argv)

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

正确检查 {} 组合。 你主要在 create{} 函数中编写了 display() 函数定义。 因此,请正确添加 {} 对。 添加保持代码缩进良好在 display() 函数定义之前添加一个结束的 '}'。

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

字符串应为 %s。

最新更新