结构体中的 疑惑。
#include<stdio.h>struct{
char name[10];
int year;
float salary;
}w[20];
main()
{
int i;
float temp;
for(i=0;i<5;i++)
{
printf("please input name:");
scanf("%s",w[i].name);
printf("please input wore year:");
scanf("%d",&w[i].year);
printf("please input salary:");
scanf("%f",&temp);
w[i].salary=temp;
}
printf("before change:\n");
for(i=0;i<5;i++)
{
printf("name:%s",w[i].name);
printf("year:%d",w[i].year);
printf("salary:%.2f",w[i].salary);
printf("\n");
}
for(i=0;i<5;i++)
if(w[i].year>30)
w[i].salary+=100;
printf("after change:\n");
for(i=0;i<5;i++)
{
printf("name:%s",w[i].name);
printf("year:%d",w[i].year);
printf("salary:%.2f",w[i].salary);
printf("\n");
}
}
为什么要这么写 scanf("%f",&temp);
w[i].salary=temp;
而不是像上面一样 这么scanf("%f",&w[i].salary) 知道的人讲下 谢谢了。