问题描述
- C语言结构数组的题,请大神看看错误出在哪里
-
#include
struct sell
{
char dm[4];
char mc[10];
int dj;
int sl;
long int je;
}sell[100];
void main()
{
int i,j,t;
long int m;
for(i=0;i
scanf("%s,%s,%4d,%5d,%5dn",&sell[i]dm,&sell[i].mc,&sell[i].dj,&sell[i].sl,&sell[i].je);
for(i=0;i
for(i=0;i
if(struct(sell[i].mc>sell[i+1].mc)
{
t=sell[i].mc;
sell[i].mc=sell[i+1].mc;
sell[i+1].mc=t;
}
else if(sell[i].mc==sell[i+1].mc)
{
if(sell[i].je>sell[i+1].je)
{
m=sell[i].je;
sell[i].je=sell[i+1].je;
sell[i+1].je=m;
}
}for(i=0;i<100;i++)
printf("%s,%s,%4d,%5d,%5dn",sell[i].dm,sell[i].mc,sell[i].dj,sell[i].sl,sell[i].je);
}
解决方案
错误多着呢
&sell[i]dm
中间少了点
struct(sell[i].mc>sell[i+1].mc
这里多了struct(
解决方案二:
for(i = 0; i < 100; i++)
{
scanf("%s,%s,%4d,%5d,%5dn",&sell[i]dm,&sell[i].mc,&sell[i].dj,&sell[i].sl,&sell[i].je)
}
for(i = 0; i < 100; i++)
{
if(sell[i].mc>sell[i+1].mc)
....
}
for循环的结构再好好看看资料吧
时间: 2024-12-06 18:54:55