鱼C论坛

 找回密码
 立即注册
查看: 1370|回复: 2

[已解决]求助一个结构体的问题

[复制链接]
发表于 2021-3-4 14:53:30 | 显示全部楼层 |阅读模式

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

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

x
  1. #include<stdio.h>
  2. #include<string.h>
  3. struct student//声明结构体类型
  4. {
  5.     int num;
  6.     char name[20];
  7.     char sex;
  8.     int age;
  9. };

  10. int main()
  11. {
  12.     struct student stu1;//声明结构体变量
  13.     struct sutdent *pst1;
  14.     pst1 = &stu1;
  15.     stu1.num = 1001;
  16.     strcpy(stu1.name,"Alex");
  17.     stu1.sex = 'M';
  18.     stu1.age = 19;
  19.     printf("num = %d name = %s sex = %c age = %c\n",
  20.     stu1.num,stu1.name,stu1.sex,stu1.age);
  21.     printf("num = %d name = %s sex = %c age = %c\n",
  22.     pst1->num,pst1->name,pst1->sex,pst1->age);
  23.     printf("num = %d name = %s sex = %c age = %c\n",
  24.     (*pst1).num,(*pst1).name,(*pst1).sex,(*pst1).age);

  25.     return 0;

  26. }
复制代码


这段程序在VS code运行报错。怎么办 我是照书上抄的

c3.c: In function 'main':
c3.c:1910:10: warning: assignment to 'struct sutdent *' from incompatible pointer type 'struct student *' [-Wincompatible-pointer-types]
     pst1 = &stu1;
          ^
c3.c:1918:9: error: dereferencing pointer to incomplete type 'struct sutdent'
     pst1->num,pst1->name,pst1->sex,pst1->age);
         ^~
最佳答案
2021-3-4 15:07:37
又一位不认真检查代码的同学


student
sutdent


1.png
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-3-4 15:07:37 | 显示全部楼层    本楼为最佳答案   
又一位不认真检查代码的同学


student
sutdent


1.png
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

 楼主| 发表于 2021-3-4 16:14:36 | 显示全部楼层
人造人 发表于 2021-3-4 15:07
又一位不认真检查代码的同学

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

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-7-16 08:45

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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