|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 西月 于 2013-1-22 15:59 编辑
- #include <stdio.h>
- struct student
- {
- char *name;
- float score[3];
- };
- void printf_student(struct student *p_stu);
- void main()
- {
-
- struct student stu;
- stu.name="Fishc.com";
- stu.score[0]=78.54;
- stu.score[1]=86.51;
- stu.score[2]=76.47;
- struct student *pstu;
- pstu=&stu;
- printf_student(pstu);
- }
- void printf_student(struct student *p_stu)
- {
- printf("Name = %s\n",p_stu->name);
- printf("Score_1 = %.2f\n",p_stu->score[0]);
- printf("Score_2 = %.2f\n",p_stu->score[1]);
- printf("Score_3 = %.2f\n",p_stu->score[2]);
- }
复制代码 错误提示 ->VC6.0
--------------------Configuration: code 111 - Win32 Debug--------------------
Compiling...
1.c
D:\code\code 111\1.c(13) : warning C4305: '=' : truncation from 'const double ' to 'float '
D:\code\code 111\1.c(14) : warning C4305: '=' : truncation from 'const double ' to 'float '
D:\code\code 111\1.c(15) : warning C4305: '=' : truncation from 'const double ' to 'float '
D:\code\code 111\1.c(16) : error C2143: syntax error : missing ';' before 'type'
D:\code\code 111\1.c(17) : error C2065: 'pstu' : undeclared identifier
D:\code\code 111\1.c(17) : warning C4047: '=' : 'int ' differs in levels of indirection from 'struct student *'
D:\code\code 111\1.c(18) : warning C4047: 'function' : 'struct student *' differs in levels of indirection from 'int '
D:\code\code 111\1.c(18) : warning C4024: 'printf_student' : different types for formal and actual parameter 1
执行 cl.exe 时出错.
code 111.exe - 1 error(s), 0 warning(s)
----------------------------------------------------------------
我看代码没什么错啊。。怎么会出现这么多错误?
问题找到了 纯C 里面的 变量都要先定义,不能中途定义 ,规定不能随拿随用!这个规定太尼玛xxx!!!
- #include <stdio.h>
- struct student
- {
- char *name;
- float score[3];
- };
- void printf_student(struct student *p_stu);
- void main()
- {
-
- struct student stu,*pstu;
- stu.name="Fishc.com";
- stu.score[0]=78.54;
- stu.score[1]=86.51;
- stu.score[2]=76.47;
- pstu=&stu;
- printf_student(pstu);
- }
- void printf_student(struct student *p_stu)
- {
- printf("Name = %s\n",p_stu->name);
- printf("Score_1 = %.2f\n",p_stu->score[0]);
- printf("Score_2 = %.2f\n",p_stu->score[1]);
- printf("Score_3 = %.2f\n",p_stu->score[2]);
- }
复制代码
|
|