鱼C论坛

 找回密码
 立即注册
查看: 1225|回复: 7

[已解决]求助呀!!1为什么在VS里会说我的poi类型不兼容呀

[复制链接]
发表于 2019-3-16 01:01:39 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define TSIZE 20

typedef struct note {
        char name[TSIZE];  //学生姓名
        char number[TSIZE];  //学生学号
        double chinese;  //语文成绩
        double english;  //英语成绩
        double math;  //数学成绩
        struct Student * next;  //定义结构指针,形成链表
       
}Student;  //定义学生类型结构,储存学生信息

void dele(Student * poi);  //删除节点
void plus(Student * poi);  //增加节点
void show(Student * poi);  //显示学生信息
void frees(Student * poi);  //清理内存
int main(void)
{
        int a;
        char copy[TSIZE];
        Student * head = NULL;
        Student * currect,* prev,*end;  //声明指针
        printf("请问要执行哪项操作:(输入对应编号)\n");
        printf("1.输入学生信息     2.删除指定学生信息\n");
        printf("3.添加学生信息     4.显示学生信息\n");
        printf("5.退出程序\n");
        scanf("%d",&a);
        while(a != 5)
        {
                switch (a)  //使用switch让用户进行选择使用
                {
                        case 1:  //让用户输入学生信息
                                        printf("学生姓名\t学生学号\t语文成绩\t数学成绩\t英语成绩(输入ctrl+z退出)\n");
                                        while(scanf("%s",copy) != EOF&&copy[0] != '\0')
                                        {
                                        currect = (Student *) malloc(sizeof(Student));
                                        if(head == NULL)
                                            head = currect;
                                        else
                                            prev->next = currect;
                                        currect->next = NULL;
                                        end = currect;
                                        strcpy(currect->name,copy);
                                        scanf("%s%lf%lf%lf",currect->number,&currect->chinese,&currect->math,&currect->english);
                                        while(getchar() != '\n')
                                            continue;
                                        prev = currect;
                                    }
                                    printf("请问要执行哪项操作:(输入对应编号)\n");
                        printf("1.输入学生信息     2.删除指定学生信息\n");
                        printf("3.添加学生信息     4.显示学生信息\n");
                        printf("5.退出程序\n");
                        scanf("%d",&a);
                                break;
                        case 2:  //让用户删除指定信息
                                dele(head);
                                printf("请问要执行哪项操作:(输入对应编号)\n");
                                scanf("%d",&a);
                                break;
                        case 3:  //让用户增加信息
                                plus(end);
                                printf("请问要执行哪项操作:(输入对应编号)\n");
                                scanf("%d",&a);
                                break;
                        case 4:  //显示信息
                                show(head);
                                printf("请问要执行哪项操作:(输入对应编号)\n");
                                scanf("%d",&a);
                                break;
                        case 5:  //结束使用
                                printf("谢谢使用\n");
                                frees(head);
                                break;
                               
                }
        }
        frees(head);  //清理内存
        return 0;
}

void dele(Student * poi)  //定义删除节点函数
{
        Student * find, * de,*save;
        char num[TSIZE];
        printf("请输入要删除信息的学生学号\n");
        scanf("%s",&num[0]);
        while(getchar() != '\n')
                continue;
        de = poi;
        save = poi;
        while(strcmp(num,de->number))
        {
                find = de;
                de = de->next;
        }
        if(poi == de)
           poi = de->next;
        else
           find->next = de->next;
        free(de);
}

void plus(Student * poi)  //定义增加节点函数
{
        printf("请输入学生信息\n");
        Student * find, *over;
        find = (Student *) malloc(sizeof(Student));
        poi->next = find;
        scanf("%s%s%lf%lf%lf",find->name,find->number,&find->chinese,&find->math,&find->english);
        find->next = NULL;
}
void show(Student * poi)  //定义显示函数
{
        while(poi != NULL)
        {
          printf("%s\t%s\t%0.2lf\t%0.2lf\t%0.2lf\n",poi->name,poi->number,poi->chinese,poi->math,poi->english);
          poi = poi->next;
    }
}
void frees(Student * poi)  //定义清理内存函数
{
        Student * save;
        save = poi;
        while(poi != NULL)
        {
                save = poi;
                poi = poi->next;
                free(save);
        }
}
最佳答案
2019-3-16 03:35:06
本帖最后由 jackz007 于 2019-3-16 03:37 编辑
ttypedef struct note {
        char name[TSIZE]      ;
        char number[TSIZE]    ;
        double chinese        ;
        double english        ;
        double math           ;
        struct Student * next ;  // 错误在这里,正确的写法是: struct node * next ;
} Student                     ;
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2019-3-16 01:03:49 | 显示全部楼层
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define TSIZE 20

typedef struct note {
        char name[TSIZE];  //学生姓名 
        char number[TSIZE];  //学生学号 
        double chinese;  //语文成绩 
        double english;  //英语成绩 
        double math;  //数学成绩 
        struct Student * next;  //定义结构指针,形成链表 
        
}Student;  //定义学生类型结构,储存学生信息 

void dele(Student * poi);  //删除节点 
void plus(Student * poi);  //增加节点 
void show(Student * poi);  //显示学生信息 
void frees(Student * poi);  //清理内存 
int main(void)
{
        int a;
        char copy[TSIZE];
        Student * head = NULL;
        Student * currect,* prev,*end;  //声明指针 
        printf("请问要执行哪项操作:(输入对应编号)\n");
        printf("1.输入学生信息     2.删除指定学生信息\n");
        printf("3.添加学生信息     4.显示学生信息\n");
        printf("5.退出程序\n");
        scanf("%d",&a);
        while(a != 5)
        {
                switch (a)  //使用switch让用户进行选择使用 
                {
                        case 1:  //让用户输入学生信息 
                                        printf("学生姓名\t学生学号\t语文成绩\t数学成绩\t英语成绩(输入ctrl+z退出)\n");
                                        while(scanf("%s",copy) != EOF&©[0] != '\0')
                                        {
                                        currect = (Student *) malloc(sizeof(Student));
                                        if(head == NULL)
                                            head = currect;
                                        else
                                            prev->next = currect;
                                        currect->next = NULL;
                                        end = currect;
                                        strcpy(currect->name,copy);
                                        scanf("%s%lf%lf%lf",currect->number,&currect->chinese,&currect->math,&currect->english);
                                        while(getchar() != '\n')
                                            continue;
                                        prev = currect;
                                    }
                                    printf("请问要执行哪项操作:(输入对应编号)\n");
                        printf("1.输入学生信息     2.删除指定学生信息\n");
                        printf("3.添加学生信息     4.显示学生信息\n");
                        printf("5.退出程序\n");
                        scanf("%d",&a);
                                break;
                        case 2:  //让用户删除指定信息 
                                dele(head);
                                printf("请问要执行哪项操作:(输入对应编号)\n");
                                scanf("%d",&a);
                                break;
                        case 3:  //让用户增加信息 
                                plus(end);
                                printf("请问要执行哪项操作:(输入对应编号)\n");
                                scanf("%d",&a);
                                break;
                        case 4:  //显示信息 
                                show(head);
                                printf("请问要执行哪项操作:(输入对应编号)\n");
                                scanf("%d",&a);
                                break;
                        case 5:  //结束使用 
                                printf("谢谢使用\n");
                                frees(head);
                                break;
                                
                }
        }
        frees(head);  //清理内存 
        return 0;
}

void dele(Student * poi)  //定义删除节点函数 
{
        Student * find, * de,*save;
        char num[TSIZE];
        printf("请输入要删除信息的学生学号\n");
        scanf("%s",&num[0]);
        while(getchar() != '\n')
                continue;
        de = poi;
        save = poi;
        while(strcmp(num,de->number))
        {
                find = de;
                de = de->next;
        }
        if(poi == de)
           poi = de->next;
        else
           find->next = de->next;
        free(de);
}

void plus(Student * poi)  //定义增加节点函数 
{
        printf("请输入学生信息\n");
        Student * find, *over;
        find = (Student *) malloc(sizeof(Student));
        poi->next = find;
        scanf("%s%s%lf%lf%lf",find->name,find->number,&find->chinese,&find->math,&find->english);
        find->next = NULL;
}
void show(Student * poi)  //定义显示函数 
{
        while(poi != NULL)
        {
          printf("%s\t%s\t%0.2lf\t%0.2lf\t%0.2lf\n",poi->name,poi->number,poi->chinese,poi->math,poi->english);
          poi = poi->next;
    }
}
void frees(Student * poi)  //定义清理内存函数 
{
        Student * save;
        save = poi;
        while(poi != NULL)
        {
                save = poi;
                poi = poi->next;
                free(save);
        }
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-3-16 03:35:06 | 显示全部楼层    本楼为最佳答案   
本帖最后由 jackz007 于 2019-3-16 03:37 编辑
ttypedef struct note {
        char name[TSIZE]      ;
        char number[TSIZE]    ;
        double chinese        ;
        double english        ;
        double math           ;
        struct Student * next ;  // 错误在这里,正确的写法是: struct node * next ;
} Student                     ;
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-3-16 07:13:02 | 显示全部楼层

可以了b( ̄▽ ̄)d ,能告诉我是为什么吗
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-3-16 10:11:04 | 显示全部楼层
SKY朱长 发表于 2019-3-16 07:13
可以了b( ̄▽ ̄)d ,能告诉我是为什么吗

     规则,遵守就好了。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-3-17 21:14:27 | 显示全部楼层
SKY朱长 发表于 2019-3-16 07:13
可以了b( ̄▽ ̄)d ,能告诉我是为什么吗

    既然你问题解决了,是不是该结束求助了?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-3-17 22:38:07 | 显示全部楼层
SKY朱长 发表于 2019-3-16 07:13
可以了b( ̄▽ ̄)d ,能告诉我是为什么吗

typedef是自定义类型,也就是说在你的代码中原本的类型本来是struct note;只不过你通过typedef将Student定义为struct note类型,那么你可以理解为在struct note里面根本不知道自己是Student类型了,也就是说你在里面用Student它不认识,所以你应该用它本来的原类型note
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-3-18 21:44:16 | 显示全部楼层
Break_L 发表于 2019-3-17 22:38
typedef是自定义类型,也就是说在你的代码中原本的类型本来是struct note;只不过你通过typedef将Student ...

懂了,谢谢
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-10-3 12:39

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表