鱼C论坛

 找回密码
 立即注册
查看: 1513|回复: 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 编辑
  1. ttypedef struct note {
  2.         char name[TSIZE]      ;
  3.         char number[TSIZE]    ;
  4.         double chinese        ;
  5.         double english        ;
  6.         double math           ;
  7.         struct Student * next ;  // 错误在这里,正确的写法是: struct node * next ;
  8. } Student                     ;
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

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

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

  14. void dele(Student * poi);  //删除节点
  15. void plus(Student * poi);  //增加节点
  16. void show(Student * poi);  //显示学生信息
  17. void frees(Student * poi);  //清理内存
  18. int main(void)
  19. {
  20.         int a;
  21.         char copy[TSIZE];
  22.         Student * head = NULL;
  23.         Student * currect,* prev,*end;  //声明指针
  24.         printf("请问要执行哪项操作:(输入对应编号)\n");
  25.         printf("1.输入学生信息     2.删除指定学生信息\n");
  26.         printf("3.添加学生信息     4.显示学生信息\n");
  27.         printf("5.退出程序\n");
  28.         scanf("%d",&a);
  29.         while(a != 5)
  30.         {
  31.                 switch (a)  //使用switch让用户进行选择使用
  32.                 {
  33.                         case 1:  //让用户输入学生信息
  34.                                         printf("学生姓名\t学生学号\t语文成绩\t数学成绩\t英语成绩(输入ctrl+z退出)\n");
  35.                                         while(scanf("%s",copy) != EOF&&copy[0] != '\0')
  36.                                         {
  37.                                         currect = (Student *) malloc(sizeof(Student));
  38.                                         if(head == NULL)
  39.                                             head = currect;
  40.                                         else
  41.                                             prev->next = currect;
  42.                                         currect->next = NULL;
  43.                                         end = currect;
  44.                                         strcpy(currect->name,copy);
  45.                                         scanf("%s%lf%lf%lf",currect->number,&currect->chinese,&currect->math,&currect->english);
  46.                                         while(getchar() != '\n')
  47.                                             continue;
  48.                                         prev = currect;
  49.                                     }
  50.                                     printf("请问要执行哪项操作:(输入对应编号)\n");
  51.                         printf("1.输入学生信息     2.删除指定学生信息\n");
  52.                         printf("3.添加学生信息     4.显示学生信息\n");
  53.                         printf("5.退出程序\n");
  54.                         scanf("%d",&a);
  55.                                 break;
  56.                         case 2:  //让用户删除指定信息
  57.                                 dele(head);
  58.                                 printf("请问要执行哪项操作:(输入对应编号)\n");
  59.                                 scanf("%d",&a);
  60.                                 break;
  61.                         case 3:  //让用户增加信息
  62.                                 plus(end);
  63.                                 printf("请问要执行哪项操作:(输入对应编号)\n");
  64.                                 scanf("%d",&a);
  65.                                 break;
  66.                         case 4:  //显示信息
  67.                                 show(head);
  68.                                 printf("请问要执行哪项操作:(输入对应编号)\n");
  69.                                 scanf("%d",&a);
  70.                                 break;
  71.                         case 5:  //结束使用
  72.                                 printf("谢谢使用\n");
  73.                                 frees(head);
  74.                                 break;
  75.                                 
  76.                 }
  77.         }
  78.         frees(head);  //清理内存
  79.         return 0;
  80. }

  81. void dele(Student * poi)  //定义删除节点函数
  82. {
  83.         Student * find, * de,*save;
  84.         char num[TSIZE];
  85.         printf("请输入要删除信息的学生学号\n");
  86.         scanf("%s",&num[0]);
  87.         while(getchar() != '\n')
  88.                 continue;
  89.         de = poi;
  90.         save = poi;
  91.         while(strcmp(num,de->number))
  92.         {
  93.                 find = de;
  94.                 de = de->next;
  95.         }
  96.         if(poi == de)
  97.            poi = de->next;
  98.         else
  99.            find->next = de->next;
  100.         free(de);
  101. }

  102. void plus(Student * poi)  //定义增加节点函数
  103. {
  104.         printf("请输入学生信息\n");
  105.         Student * find, *over;
  106.         find = (Student *) malloc(sizeof(Student));
  107.         poi->next = find;
  108.         scanf("%s%s%lf%lf%lf",find->name,find->number,&find->chinese,&find->math,&find->english);
  109.         find->next = NULL;
  110. }
  111. void show(Student * poi)  //定义显示函数
  112. {
  113.         while(poi != NULL)
  114.         {
  115.           printf("%s\t%s\t%0.2lf\t%0.2lf\t%0.2lf\n",poi->name,poi->number,poi->chinese,poi->math,poi->english);
  116.           poi = poi->next;
  117.     }
  118. }
  119. void frees(Student * poi)  //定义清理内存函数
  120. {
  121.         Student * save;
  122.         save = poi;
  123.         while(poi != NULL)
  124.         {
  125.                 save = poi;
  126.                 poi = poi->next;
  127.                 free(save);
  128.         }
  129. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-3-16 03:35:06 | 显示全部楼层    本楼为最佳答案   
本帖最后由 jackz007 于 2019-3-16 03:37 编辑
  1. ttypedef struct note {
  2.         char name[TSIZE]      ;
  3.         char number[TSIZE]    ;
  4.         double chinese        ;
  5.         double english        ;
  6.         double math           ;
  7.         struct Student * next ;  // 错误在这里,正确的写法是: struct node * next ;
  8. } Student                     ;
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

可以了b( ̄▽ ̄)d ,能告诉我是为什么吗
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

     规则,遵守就好了。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

    既然你问题解决了,是不是该结束求助了?
小甲鱼最新课程 -> https://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
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

懂了,谢谢
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-6-17 09:29

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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