会不会是TC的bug?
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 35
typedef struct tagSTU
{
char id[28];
float scores[4];
float avg;
float tot;
}STU;
STU* createSTU()
{
STU *stu=(STU*)malloc(sizeof(STU));
printf("Please input the ID\n");
scanf("%s%f%f%f%f",stu->id,&stu->scores[0],&stu->scores[1],\
&stu->scores[2],&stu->scores[3]);
stu->tot=stu->scores[0]+stu->scores[1]+stu->scores[2]+stu->scores[3];
stu->avg=stu->tot/4;
return stu;
}
void Equal(STU *a,STU *b)
{
a->scores[0]=b->scores[0];
a->scores[1]=b->scores[1];
a->scores[2]=b->scores[2];
a->scores[3]=b->scores[3];
strcpy(a->id,b->id);
a->avg=b->avg;
a->tot=b->tot;
}
void Sort(STU *addr,int num)
{
int i,j;
STU temp;
for(i=num-1;i>0;i--)
{
for(j=0;j<i;j++)
{
if(addr[j].tot<addr[j+1].tot)
{
Equal(&temp,&addr[j]);
Equal(&addr[j],&addr[j+1]);
Equal(&addr[j+1],&temp);
}
}
}
}
void Show(STU *addr,int num)
{
int i=0;
while(i<num)
{
printf("id:%s\n%.2f %.2f %.2f %.2f %.2f %.2f\n",addr[i].id,addr[i].scores[0],\
addr[i].scores[1],addr[i].scores[2],addr[i].scores[3],addr[i].avg,addr[i].tot);
i++;
}
}
void Showsub(STU *addr,int num,int s)
{
int i=0;
while(i<num&&i<5)
{
if(addr[i].scores[s]>89)
printf("id:%s\n%.2f %.2f %.2f %.2f %.2f %.2f\n",addr[i].id,addr[i].scores[0],\
addr[i].scores[1],addr[i].scores[2],addr[i].scores[3],addr[i].avg,addr[i].tot);
i++;
}
}
int main()
{
int num,i=0,s=0;
STU stu[MAX];
printf("Please input the amount of the student(<35)\n");
scanf("%d",&num);
if(num<1||num>MAX)return -1;
while(i<num)
{
stu[i]=*createSTU();
i++;
}
Sort(stu,num);
Show(stu,num);
printf("Please input the number of subject(0-3)\n");
scanf("%d",&s);
if(s<0||s>3)return -1;
Showsub(stu,num,s);
system("PAUSE");
return 0;
}
这个程序在TC下编译连接没有错,运行时会出现这样的情况:
Please input the amount of the students(<35)
1
Please input the ID
12 78 79 80 81
scanf:floating point formats not linked
Abnormal program termination
而在Dev-C++环境下则运行正常
Please input the amount of the students(<35)
1
Please input the ID
12 78 79 80 81
id:12
78.00 79.00 80.00 81.00 79.50 318.00
Please input the number of subject(0-3)
2
请按任意键继续...
问题点数:30、回复次数:5Top
1 楼duduhaha(三人行必有我师)回复于 2006-03-18 18:44:42 得分 20
对,tc2对浮点数的支持不好。
对于结构体里嵌套浮点数组,是会出问题的。
这么用。
scanf("%f",a);
stu->scores[0] = a;
Top
2 楼skywoody()回复于 2006-03-18 19:19:57 得分 0
TC确实是有一些bug的
当年写东西调试了N久老出错,后来才知道是tc的一个bug
郁闷死
用gcc多好,为何还用tc呢?Top
3 楼jixingzhong(瞌睡虫·星辰)回复于 2006-03-18 19:20:59 得分 10
为了减少资源耗费,
tc 默认不连接浮点库 ...
解决办法,
可以在 main中,
变量定义之后, 浮点输入之前,
增加一个浮点操作,
比如 sin(0.0) ...Top
4 楼tianhuo_soft(悬崖边的舞者)回复于 2006-03-18 20:33:00 得分 0
我试了 所有的float该成int就行~! 充分说明TC对float支持的能力Top
5 楼hyz0906(超超)回复于 2006-03-19 10:36:34 得分 0
谢谢大家!Top




