马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
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);
^~
又一位不认真检查代码的同学
student
sutdent
|