学编程的盆子 发表于 2021-3-4 14:53:30

求助一个结构体的问题

#include<stdio.h>
#include<string.h>
struct student//声明结构体类型
{
    int num;
    char name;
    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

学编程的盆子 发表于 2021-3-4 16:14:36

人造人 发表于 2021-3-4 15:07
又一位不认真检查代码的同学




谢谢谢谢大佬
页: [1]
查看完整版本: 求助一个结构体的问题