求助高手(关于结构)

Timmy_Y 2012-05-21 10:13:17
struct table man[20];
{
char name[10];
int score;
};
#include<stdio.h>
void main()
{ char a[100];
int i,j,n,i,temp;
scanf("%d\n",&n);
for(i=0;i<n;i++)
{
gets(a);
for(j=0;a[j]!=',',j++)
man[i].name[j]=a[j];
man[i].score=(a[j+1]-'0')*10+a[j+2]-'0';
}
for(i=0;i<n-1;i++)
{
r=i;
for(j=i+1;j<n;j++)
if(man[j].score>man[i].score)
r=j;
temp=man[i].score
man[i].score=man[r].score;
man[r].score=temp;
}
for(i=0;i<n;i++)
printf("%s,%d\n",man[i].name,man[i].score);
}

我这个程序编译总是不成功,但我不知道错在哪里,求帮看看
...全文
83 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
pathuang68 2012-05-22
  • 打赏
  • 举报
回复

struct table man[20]; // 1. 这里绝对不可以加分号,2. 定义结构体数组也能在这里
{
char name[10];
int score;
};

参考做法:
struct table
{
char name[10];
int score;
};

struct table man[20];
lkxd2011 2012-05-22
  • 打赏
  • 举报
回复
#include<stdio.h>

struct table
{
char name[10];
int score;
};
table man[20];
void main()
{ char a[100];
int r,j,n,i,temp;
scanf("%d\n",&n);
for(i=0;i<n;i++)
{
gets(a);
for(j=0;a[j]!=',';j++)
man[i].name[j]=a[j];
man[i].score=(a[j+1]-'0')*10+a[j+2]-'0';
}
for(i=0;i<n-1;i++)
{
r=i;
for(j=i+1;j<n;j++)
if(man[j].score>man[i].score)
r=j;
temp=man[i].score;
man[i].score=man[r].score;
man[r].score=temp;
}
for(i=0;i<n;i++)
printf("%s,%d\n",man[i].name,man[i].score);
}


可以编译通过了~~
你这太多的错误,全是小问题,我就不一一指出了,自己对着我这看吧~~
关于结构体定义结构数组,可以这样,先定义结构体,然后定义结构体对象的数组就好了~~
struct table
{
char name[10];
int score;
};
table man[20];
Timmy_Y 2012-05-22
  • 打赏
  • 举报
回复
那我想定义一个结构数组,该如何是好呢
西山小月 2012-05-21
  • 打赏
  • 举报
回复
struct table man[20];
没见过这么定义的

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧