首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

郁闷!该如何解决

2012-03-31 
郁闷!/*输入五个学生的数据,并打印出来*/#includestdio.htypedefstruct{longnumcharname[10]floatscor

郁闷!
/*输入五个学生的数据,并打印出来*/
#include   <stdio.h>
typedef   struct   {
long   num;
char   name[10];
float   score0;
float   score1;
float   score2;
                }DATA;  
main(){
DATA   sd[5];
int   i;
puts( "Please   5   students   Number   Name   and   Score ");
for   (i=0;i <5;i++)
scanf( "%ld   %s   %f   %f   %f ",&sd[i].num,sd[i].name,&sd[i].score0,&sd[i].score1,&sd[i].score2);

for   (i=0;i <5;i++)
printf( "%ld   %s   %f   %f   %f\n ",sd[i].num,sd[i].name,sd[i].score0,sd[i].score1,sd[i].score2);
}
/*
在turbo   2.0下运行
输入   120   china   78.0   80.3   72.4 <回车>
出现出错提示:
scanf   :   floating   point   formats   not   linked
Abnormal   program   termination
而在VC下运行没有出错提示!
*/

[解决办法]
修改后的代码如下,在TC上运行过了,没问题。。。

#include <stdio.h>
#include <stdlib.h>
typedef struct
{
long num;
char name[10];
float score0;
float score1;
float score2;
}DATA;
main()
{
DATA sd[5];
int i;
float a,b,c;
puts( "Please 5 students Number Name and Score ");
for (i=0;i <5;i++)
{
scanf( "%ld %s %f %f %f ",&sd[i].num,sd[i].name,&a,&b,&c);
sd[i].score0 = a;
sd[i].score1 = b;
sd[i].score2 = c;
}

for (i=0;i <5;i++)
printf( "%ld %s %f %f %f\n ",sd[i].num,sd[i].name,sd[i].score0,sd[i].score1,sd[i].score2);
}

热点排行