C语言编程问题,有关scanf输入的

来源:百度知道 编辑:UC知道 时间:2024/06/08 09:18:16
#define PR printf("\n")
#include "stdio.h"
void main()
{
struct student
{
char id[12];
char name[12];
float s1;
float s2;
float s3;
};
struct student stu[10],*p;
int i;
p=stu;
for(i=0;i<10;i++)
{
printf("Information Of Student[%2d]:",i+1);
PR;
printf("ID:\n");
scanf("%s",p->id);
printf("Name:\n");
scanf("%s",p->name);
printf("Score of Subject-1:\n");
scanf("%f",p->s1);
printf("Score of Subject-2:\n");
scanf("%f",p->s2);
printf("Score of Subject-3:\n");
scanf("%f",p->s3);
}
}
上面这段程序编译和连接都没问题,为什么在执行的时候就报错啊,而且还不正常推出
高手啊( ⊙ o ⊙ )啊!
看看吧!!!
不好意思拷贝错了,每个scanf中都是有&的如:
scanf("%f",&p->s1);
即使这样,也报错!

这是tc本身的bug,把下面这个复制到程序里main函数开头就可以了:成功连接浮点库,程序运行的时候就可以正常退出了。代码是没有问题的。
float arg,*point=&arg;

/*示例*/

void main()
{
float arg,*point=&arg;//只是为了连接浮点库正常,不影响下面代码运行。

struct student

scanf("%f",p->s1);
printf("Score of Subject-2:\n");
scanf("%f",p->s2);
printf("Score of Subject-3:\n");
scanf("%f",p->s3);
改成:
scanf("%f",&p->s1);
printf("Score of Subject-2:\n");
scanf("%f",&p->s2);
printf("Score of Subject-3:\n");
scanf("%f",&p->s3);

scanf("%s",&(p->name));
都改为这种形式应该行了吧?
在不确定优先级的情况下最好加()

很显然啊!scanf的错误啊!
如scanf("%s",p->id);
改为scanf("%s",&p->id);
其他的也一样!

#define PR printf("\n")
#include "stdio.h"
void main()
{
struct student