鱼C论坛

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

代码问题?OR编译器问题?

[复制链接]
发表于 2013-1-22 15:42:12 | 显示全部楼层 |阅读模式

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

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

x
本帖最后由 西月 于 2013-1-22 15:59 编辑
  1. #include <stdio.h>
  2. struct student
  3. {
  4.       char *name;
  5.       float score[3];
  6. };
  7. void printf_student(struct student *p_stu);
  8. void main()
  9. {
  10.       
  11.       struct student stu;
  12.       stu.name="Fishc.com";
  13.       stu.score[0]=78.54;
  14.       stu.score[1]=86.51;
  15.       stu.score[2]=76.47;
  16.       struct student *pstu;
  17.       pstu=&stu;
  18.       printf_student(pstu);
  19. }
  20. void printf_student(struct student *p_stu)
  21. {
  22.       printf("Name = %s\n",p_stu->name);
  23.       printf("Score_1 = %.2f\n",p_stu->score[0]);
  24.       printf("Score_2 = %.2f\n",p_stu->score[1]);
  25.       printf("Score_3 = %.2f\n",p_stu->score[2]);
  26. }
复制代码
错误提示 ->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!!!

  1. #include <stdio.h>
  2. struct student
  3. {
  4.       char *name;
  5.       float score[3];
  6. };
  7. void printf_student(struct student *p_stu);
  8. void main()
  9. {
  10.       
  11.       struct student stu,*pstu;
  12.       stu.name="Fishc.com";
  13.       stu.score[0]=78.54;
  14.       stu.score[1]=86.51;
  15.       stu.score[2]=76.47;
  16.       pstu=&stu;
  17.       printf_student(pstu);
  18. }
  19. void printf_student(struct student *p_stu)
  20. {
  21.       printf("Name = %s\n",p_stu->name);
  22.       printf("Score_1 = %.2f\n",p_stu->score[0]);
  23.       printf("Score_2 = %.2f\n",p_stu->score[1]);
  24.       printf("Score_3 = %.2f\n",p_stu->score[2]);
  25. }
复制代码


小甲鱼最新课程 -> https://ilovefishc.com
发表于 2013-1-22 16:07:16 | 显示全部楼层
不是C的规定,是C++后来增加了可以随处声明定义~
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2013-1-22 17:44:06 | 显示全部楼层
:lol习惯了C++,突然让我写C,这种规定用得好不爽!
小甲鱼最新课程 -> https://ilovefishc.com
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2025-8-8 22:03

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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