结构体排序
#include<stdio.h>#include<stdlib.h>
struct commodity
{
char number;
char name;
int the_first_quarter;
int the_second_quarter;
int the_third_quarter;
int average;
}com;
int main()
{
FILE *fp;
struct commodity a;
scanf("%s,%s,%d,%d,%d,%d",com.number,com.name,&com.the_first_quarter,&com.the_second_quarter,&com.the_third_quarter,&com.average);
a=com;
printf("%s,%s,%d,%d,%d,%d",a.number,a.name,a.the_first_quarter,a.the_second_quarter,a.the_third_quarter,a.average);
return 0;
}
//为什么输入和输出不一样? 你输入的内容都赋值给com.number了,系统认为你输入的是字符串
前10个是com.number,因为其只占10个字节,所以剩下的会开始分配给剩下的 #include<stdio.h>
#include<stdlib.h>
struct commodity
{
char number;
char name;
int the_first_quarter;
int the_second_quarter;
int the_third_quarter;
int average;
}com;
int main()
{
FILE*fp;
struct commodity a;
scanf("%s", com.number);
getchar();
scanf("%s", com.name);
getchar();
scanf("%d,%d,%d,%d",&com.the_first_quarter,&com.the_second_quarter,&com.the_third_quarter,&com.average);
a=com;
printf("%s\n", a.number);
printf("%s\n%s\n%d,%d,%d,%d",a.number,a.name,a.the_first_quarter,a.the_second_quarter,a.the_third_quarter,a.average);
return 0;
} 巴巴鲁 发表于 2021-3-11 11:19
我....想{:10_285:}起来了,说的好,%S不能连用否则,会把,当成字符串
页:
[1]