枫叶之声235 2021-04-16 16:00 采纳率: 100%
浏览 40
已采纳

有哪位大佬能帮帮看看这几个错误是怎么回事,感激不尽

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define _CRT_SECURE_NO_WARNINGS
struct student{
    char name[20];
    char num[20];//学号,姓名,性别,楼栋号,宿舍号,出发地(从哪出发
                 //返校),身体状况,并写入文件。
    int _class;
    char sex[4];
    char telephone[20];
    //double a;
    char loudong[20];
    int sushe;

};

struct stu_node{
    struct student data;
    struct stu_node *next;
};

//链表操作函数区域
struct stu_node* buildlist()    //创建链表
{
    struct stu_node* head = (struct stu_node*)malloc(sizeof(struct stu_node));//为表头动态内存分配
    head->next = NULL;            //初始化表头为NULL
    return head;                //返回值为头指针
}

struct stu_node* buildnode(struct student data)//创建学生结点
{
    struct stu_node* newnode = (struct stu_node*)malloc(sizeof(struct stu_node));//新建节点动态内存分配
    newnode->data = data;        //新建学生信息初始化
    newnode->next = NULL;        //新建学生节点的next初始化为NULL
    return newnode;                //返回值为新建的学生节点
}

void insertnode(struct stu_node* head, struct student data)//插入节点,头插法(新建的节点放在最前面)
{
    struct stu_node* newnode = buildnode(data);    //利用创建节点函数创建一个节点
    newnode->next = head->next;                    //头插法将新节点插入链表
    head->next = newnode;
}

/*void deletenode(struct stu_node* head, char* num)//删除给定学号的学生节点
{
    struct stu_node*  deletenodeFront= head;
    struct stu_node*  deletenode = head->next;
    while(strcmp(deletenode->data.num,num)){    //寻找学号为指定学号的节点
        deletenodeFront = deletenode;
        deletenode = deletenode->next;
    }
    deletenodeFront->next = deletenode->next;    //删除实现的操作
    free(deletenode);
}*/
void deletenode(struct stu_node* head,char*name)
{
struct stu_node*  deletenodeFront= head;
    struct stu_node*  deletenode = head->next;
    while(strcmp(deletenode->data.name,name)){    //寻找学号为指定学号的节点
        deletenodeFront = deletenode;
        deletenode = deletenode->next;
    }
    deletenodeFront->next = deletenode->next;    //删除实现的操作
    free(deletenode);
}


//文件操作函数区域
void readstudent(struct stu_node* head, char *filename)//读取文件操作
{
    FILE *read=NULL;
    struct student temp;
    read=fopen(filename,"r");                             //以”只读“的方式打开文件
    if(read == NULL)
        read = fopen(filename,"w+");                    //第一次打开文件以“建立新文本文件进行读\写”的方式打开
    while(fscanf(read,"%s\t%s\t%d\t%s\t%s\t%s\t%d\n",temp.name,temp.num,&temp._class,temp.sex,temp.telephone,temp.loudong,&temp.sushe)!=EOF){
        insertnode(head,temp);//&temp.a
    }
    fclose(read);
    return;//关闭文件
}

void writestudent(struct stu_node* head, char *filename)//写入文件操作
{
    FILE *write=NULL;
    struct stu_node *pHead;
    pHead = head->next;
    write=fopen(filename,"w");                            //以“建文本文件只进行写”的方式打开
    while(pHead){
        fprintf(write,"%s\t%s\t%d\t%s\t%s\t%s\t%d\n",pHead->data.name,pHead->data.num,pHead->data._class,pHead->data.sex,pHead->data.telephone,pHead->data.loudong,pHead->data.sushe);
        pHead = pHead->next;
    }
    fclose(write);    
    return;//关闭文件
}

void printList(struct stu_node *head)
{
    struct stu_node *pMove = head->next;
    printf("姓名    学号    班级    性别     电话      楼栋   宿舍   \n");
    while(pMove){
        printf("%s\t%s\t%d\t%s\t%s\t%s\t%d\n",
        pMove->data.name,pMove->data.num,pMove->data._class,pMove->data.sex,pMove->data.telephone,pMove->data.loudong,pMove->data.sushe);
        pMove = pMove->next; 
    }
    printf("\n");
}

struct node* searchstudent(struct stu_node *head, char *studentname)
{
    struct stu_node *pMove = head->next;
    //&& 短路现象
    while (pMove != NULL&&strcmp(pMove->data.name, studentname))
    {
        pMove = pMove->next;
    }
    return pMove;        //NULL 没找到
}


void menu()
{
    printf("---------------------------------------------\n");
    printf("\t\t0.退出系统\n");
    printf("\t\t1.录入信息\n");
    printf("\t\t2.浏览信息\n");
    printf("\t\t3.修改信息\n");
    printf("\t\t4.查找信息\n");
    printf("\t\t5.删除信息\n");
    printf("\t\t6.总览信息\n");
    printf("---------------------------------------------\n");
}

struct stu_node *head; 

void keydown()
{
    int userKey = 0;
    struct student userData;
    int sum;
    //double ave_grade;
    //int elx_sum;
    scanf("%d",&userKey);
    switch(userKey)
    {
        case 0:
            printf("-----------【退出系统】------------\n");
            printf("正常退出\n");
            system("pause");
            exit(0);
            break;
        case 1:
            printf("-----------【录入信息】------------\n");
            printf("请输入以下学生信息\n");
            printf("姓名  学号   班级  性别   电话   楼栋   宿舍\n");
            scanf("%s %s %d %s %s %s %d",userData.name,userData.num,&userData._class,userData.sex,userData.telephone,userData.loudong,&userData.sushe);
            insertnode(head,userData);
            break;    
        case 2:
            printf("-----------【浏览信息】------------\n");
            printList(head);
            break;
        case 3:
            printf("-----------【修改信息】------------\n");

        printf("\n\t\t【修改学生信息】\n");  //链表的修改
        printf("\t\t按照姓名修改,请输入要修改学生的姓名\n");
        scanf("%s", userData.name);
        if (searchstudent(head, userData.name) == NULL)
        {
            printf("未找到相关信息,无法修改!\n");
        }
        else
        {
            printf("请输入信息妃子信息(姓名,学号,班级,性别,电话,楼栋,宿舍)\n");
            scanf("%s%s%d%s%s%s%d", searchstudent(head, userData.name)->temp.name,
                searchstudent(head, userData.name)->temp.num,
                searchstudent(head, userData.name)->temp._class,
                searchstudent(head, userData.name)->temp.sex,
                searchstudent(head, userData.name)->temp.telephone,
                searchstudent(head, userData.name)->temp.loudong,
                searchstudent(head, userData.name)->temp.sushe);
                
          writestudent(head,"student");
          printf("修改成功!\n");
        }
        break;
    default:


            break;
        case 4:
            printf("-----------【查找信息】------------\n");
            break;
        case 5:
            printf("-----------【删除信息】------------\n");
            printf("请输入删除学生的姓名\n");
            scanf("%s",userData.name);
            deletenode(head,userData.name);
            break;
        case 6:
            printf("-----------【总览信息】------------\n");
            printf("学生总数\n");
            /*Class_Statisics(head,&sum,&ave_grade,&elx_sum);*/
            printf("%d",sum);
            /*printf("%d\t  %.1lf\t    %d\n",sum,ave_grade,elx_sum);*/ 
            break; 
    }
}
int main()
{    
    head = buildlist();
    readstudent(head,"student");
    while(1){
        menu();
        keydown();
        writestudent(head,"student");
        system("pause");
        system("cls"); 
    }
    return 0;
}
错误提示

--------------------Configuration: xuexin - Win32 Debug--------------------
Compiling...
xuexin.c
C:\Users\ren200119\Desktop\xuexin\xuexin.c(121) : warning C4133: 'return' : incompatible types - from 'struct stu_node *' to 'struct node *'
C:\Users\ren200119\Desktop\xuexin\xuexin.c(180) : error C2037: left of 'temp' specifies undefined struct/union 'node'
C:\Users\ren200119\Desktop\xuexin\xuexin.c(181) : error C2037: left of 'temp' specifies undefined struct/union 'node'
C:\Users\ren200119\Desktop\xuexin\xuexin.c(182) : error C2037: left of 'temp' specifies undefined struct/union 'node'
C:\Users\ren200119\Desktop\xuexin\xuexin.c(183) : error C2037: left of 'temp' specifies undefined struct/union 'node'
C:\Users\ren200119\Desktop\xuexin\xuexin.c(184) : error C2037: left of 'temp' specifies undefined struct/union 'node'
C:\Users\ren200119\Desktop\xuexin\xuexin.c(185) : error C2037: left of 'temp' specifies undefined struct/union 'node'
C:\Users\ren200119\Desktop\xuexin\xuexin.c(186) : error C2037: left of 'temp' specifies undefined struct/union 'node'
执行 cl.exe 时出错.

xuexin.obj - 1 error(s), 0 warning(s)
 

  • 写回答

5条回答 默认 最新

  • 毛惜时 2021-04-16 16:44
    关注

    帮你修改后,可以运行了。

    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    #define _CRT_SECURE_NO_WARNINGS
    struct student{
        char name[20];
        char num[20];//学号,姓名,性别,楼栋号,宿舍号,出发地(从哪出发
                     //返校),身体状况,并写入文件。
        int _class;
        char sex[4];
        char telephone[20];
        //double a;
        char loudong[20];
        int sushe;
    
    };
    
    struct stu_node{
        struct student data;
        struct stu_node *next;
    };
    
    //链表操作函数区域
    struct stu_node* buildlist()    //创建链表
    {
        struct stu_node* head = (struct stu_node*)malloc(sizeof(struct stu_node));//为表头动态内存分配
        head->next = NULL;            //初始化表头为NULL
        return head;                //返回值为头指针
    }
    
    struct stu_node* buildnode(struct student data)//创建学生结点
    {
        struct stu_node* newnode = (struct stu_node*)malloc(sizeof(struct stu_node));//新建节点动态内存分配
        newnode->data = data;        //新建学生信息初始化
        newnode->next = NULL;        //新建学生节点的next初始化为NULL
        return newnode;                //返回值为新建的学生节点
    }
    
    void insertnode(struct stu_node* head, struct student data)//插入节点,头插法(新建的节点放在最前面)
    {
        struct stu_node* newnode = buildnode(data);    //利用创建节点函数创建一个节点
        newnode->next = head->next;                    //头插法将新节点插入链表
        head->next = newnode;
    }
    
    /*void deletenode(struct stu_node* head, char* num)//删除给定学号的学生节点
    {
        struct stu_node*  deletenodeFront= head;
        struct stu_node*  deletenode = head->next;
        while(strcmp(deletenode->data.num,num)){    //寻找学号为指定学号的节点
            deletenodeFront = deletenode;
            deletenode = deletenode->next;
        }
        deletenodeFront->next = deletenode->next;    //删除实现的操作
        free(deletenode);
    }*/
    void deletenode(struct stu_node* head,char*name)
    {
    struct stu_node*  deletenodeFront= head;
        struct stu_node*  deletenode = head->next;
        while(strcmp(deletenode->data.name,name)){    //寻找学号为指定学号的节点
            deletenodeFront = deletenode;
            deletenode = deletenode->next;
        }
        deletenodeFront->next = deletenode->next;    //删除实现的操作
        free(deletenode);
    }
    
    
    //文件操作函数区域
    void readstudent(struct stu_node* head, char *filename)//读取文件操作
    {
        FILE *read=NULL;
        struct student temp;
        read=fopen(filename,"r");                             //以”只读“的方式打开文件
        if(read == NULL)
            read = fopen(filename,"w+");                    //第一次打开文件以“建立新文本文件进行读\写”的方式打开
        while(fscanf(read,"%s\t%s\t%d\t%s\t%s\t%s\t%d\n",temp.name,temp.num,&temp._class,temp.sex,temp.telephone,temp.loudong,&temp.sushe)!=EOF){
            insertnode(head,temp);//&temp.a
        }
        fclose(read);
        return;//关闭文件
    }
    
    void writestudent(struct stu_node* head, char *filename)//写入文件操作
    {
        FILE *write=NULL;
        struct stu_node *pHead;
        pHead = head->next;
        write=fopen(filename,"w");                            //以“建文本文件只进行写”的方式打开
        while(pHead){
            fprintf(write,"%s\t%s\t%d\t%s\t%s\t%s\t%d\n",pHead->data.name,pHead->data.num,pHead->data._class,pHead->data.sex,pHead->data.telephone,pHead->data.loudong,pHead->data.sushe);
            pHead = pHead->next;
        }
        fclose(write);    
        return;//关闭文件
    }
    
    void printList(struct stu_node *head)
    {
        struct stu_node *pMove = head->next;
        printf("姓名    学号    班级    性别     电话      楼栋   宿舍   \n");
        while(pMove){
            printf("%s\t%s\t%d\t%s\t%s\t%s\t%d\n",
            pMove->data.name,pMove->data.num,pMove->data._class,pMove->data.sex,pMove->data.telephone,pMove->data.loudong,pMove->data.sushe);
            pMove = pMove->next; 
        }
        printf("\n");
    }
    
    struct stu_node* searchstudent(struct stu_node *head, char *studentname)
    {
        struct stu_node *pMove = head->next;
        //&& 短路现象
        while (pMove != NULL&&strcmp(pMove->data.name, studentname))
        {
            pMove = pMove->next;
        }
        return pMove;        //NULL 没找到
    }
    
    
    void menu()
    {
        printf("---------------------------------------------\n");
        printf("\t\t0.退出系统\n");
        printf("\t\t1.录入信息\n");
        printf("\t\t2.浏览信息\n");
        printf("\t\t3.修改信息\n");
        printf("\t\t4.查找信息\n");
        printf("\t\t5.删除信息\n");
        printf("\t\t6.总览信息\n");
        printf("---------------------------------------------\n");
    }
    
    struct stu_node *head; 
    
    void keydown()
    {
        int userKey = 0;
        struct student userData;
    //    int sum;
        //double ave_grade;
        //int elx_sum;
        scanf("%d",&userKey);
        switch(userKey)
        {
            case 0:
                printf("-----------【退出系统】------------\n");
                printf("正常退出\n");
                system("pause");
                exit(0);
                break;
            case 1:
                printf("-----------【录入信息】------------\n");
                printf("请输入以下学生信息\n");
                printf("姓名  学号   班级  性别   电话   楼栋   宿舍\n");
                scanf("%s %s %d %s %s %s %d",userData.name,userData.num,&userData._class,userData.sex,userData.telephone,userData.loudong,&userData.sushe);
                insertnode(head,userData);
                break;    
            case 2:
                printf("-----------【浏览信息】------------\n");
                printList(head);
                break;
            case 3:
                printf("-----------【修改信息】------------\n");
    
            printf("\n\t\t【修改学生信息】\n");  //链表的修改
            printf("\t\t按照姓名修改,请输入要修改学生的姓名\n");
            scanf("%s", userData.name);
            if (searchstudent(head, userData.name) == NULL)
            {
                printf("未找到相关信息,无法修改!\n");
            }
            else
            {
                printf("请输入信息妃子信息(姓名,学号,班级,性别,电话,楼栋,宿舍)\n");
                scanf("%s%s%d%s%s%s%d", searchstudent(head, userData.name)->data.name,
                    searchstudent(head, userData.name)->data.num,
                    searchstudent(head, userData.name)->data._class,
                    searchstudent(head, userData.name)->data.sex,
                    searchstudent(head, userData.name)->data.telephone,
                    searchstudent(head, userData.name)->data.loudong,
                    searchstudent(head, userData.name)->data.sushe);
                    
              writestudent(head,"student");
              printf("修改成功!\n");
            }
            break;
        default:
    
    
                break;
            case 4:
                printf("-----------【查找信息】------------\n");
                break;
            case 5:
                printf("-----------【删除信息】------------\n");
                printf("请输入删除学生的姓名\n");
                scanf("%s",userData.name);
                deletenode(head,userData.name);
                break;
            case 6:
                printf("-----------【总览信息】------------\n");
                printf("学生总数\n");
                /*Class_Statisics(head,&sum,&ave_grade,&elx_sum);*/
                //printf("%d",sum);
                /*printf("%d\t  %.1lf\t    %d\n",sum,ave_grade,elx_sum);*/ 
                break; 
        }
    }
    int main()
    {    
        head = buildlist();
        readstudent(head,"student");
        while(1){
            menu();
            keydown();
            writestudent(head,"student");
            system("pause");
            system("cls"); 
        }
        return 0;
    }
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!