|
|
1鱼币
#include "stdio.h"
#include "string.h"
typedef struct Student
{
int age;
int sid;
char name[20];
} ST,*PST;
void main()
{
ST student;
student.age=17;
student.sid=55555;
strcpy(student.name,"lose");
printf("name:%s age=%d sid=%d\n",student.name,student.age,student.sid);
PST pst=&student;
strcpy(pst->name,"xtr");
pst->age=19;
pst->sid=18181;
printf("name:%s age=%d sid=%d\n",student.name,student.age,student.sid);
printf("%c%c%c%c\n",student.name[0],student.name[1],student.name[2],student.name[3]);
}
//这个程序中用typedef给结构体起了个别名ST,还有就是指向该结构体的指针类型名PST,但是为什么编译的时候还会出现这样的问题呢:
--------------------Configuration: main - Win32 Debug--------------------
Compiling...
main.c
F:\C语言\code\空白测试程序\main.c(18) : error C2275: 'PST' : illegal use of this type as an expression
F:\C语言\code\空白测试程序\main.c(9) : see declaration of 'PST'
F:\C语言\code\空白测试程序\main.c(18) : error C2146: syntax error : missing ';' before identifier 'pst'
F:\C语言\code\空白测试程序\main.c(18) : error C2065: 'pst' : undeclared identifier
F:\C语言\code\空白测试程序\main.c(18) : warning C4047: '=' : 'int ' differs in levels of indirection from 'struct Student *'
F:\C语言\code\空白测试程序\main.c(19) : error C2223: left of '->name' must point to struct/union
F:\C语言\code\空白测试程序\main.c(19) : error C2198: 'strcpy' : too few actual parameters
F:\C语言\code\空白测试程序\main.c(20) : error C2223: left of '->age' must point to struct/union
F:\C语言\code\空白测试程序\main.c(21) : error C2223: left of '->sid' must point to struct/union
执行 cl.exe 时出错.
求大神指导,感激不尽
|
最佳答案
查看完整内容
C语言函数声明要放在最前面,试试将后缀名改为.cpp就可以了,你用的应该是vc6吧
如果你坚持要用C语言,那就把PST pst;这句放在前面,后面再直接使用
|