鱼C论坛

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

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

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

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

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

x
#include<stdio.h>
#include<string.h>
struct student//声明结构体类型
{
    int num;
    char name[20];
    char sex;
    int age;
};

int main()
{
    struct student stu1;//声明结构体变量
    struct sutdent *pst1;
    pst1 = &stu1;
    stu1.num = 1001;
    strcpy(stu1.name,"Alex");
    stu1.sex = 'M';
    stu1.age = 19;
    printf("num = %d name = %s sex = %c age = %c\n",
    stu1.num,stu1.name,stu1.sex,stu1.age);
    printf("num = %d name = %s sex = %c age = %c\n",
    pst1->num,pst1->name,pst1->sex,pst1->age);
    printf("num = %d name = %s sex = %c age = %c\n",
    (*pst1).num,(*pst1).name,(*pst1).sex,(*pst1).age);

    return 0;

}

这段程序在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
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

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


student
sutdent


1.png
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

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

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

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-9-22 11:26

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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