你的失误:
1.代码写的太乱,毫无缩进,可读性极差
2.使用了strlen()就必须有头文件,malloc也必须有
3.write()并不需要返回值,void wrrite()就行
我给你改了,自己看看
#include
#include
#include
#define numlen 10
#define scorelen 5
#define total 3
struct achievement
{
char *name;
char number[numlen];
int score[scorelen];
};
struct achievement stu[total];
int read(struct achievement *stu)
{
int i, m, len, num;
char buf[40];
printf(“please input name:\n”);
if (scanf(“%s”, buf) == 1)
{
len = strlen(buf);
stu->name = (char *)malloc(len + 1);
strcpy(stu->name, buf);
}
else return 0;
printf(“please input number:\n”);
if (scanf(“%s”, buf) == 1)
strcpy(stu->number, buf);
else
{
free(stu->name);
return 0;
}
printf(“please input score”);
for (i &#61; 0; i <5; i&#43;&#43;)
{
if (scanf(“%d”, &num) &#61;&#61; 1)
stu->score[i] &#61; num;
else
break;
}
for (m &#61; i; m <&#61; 4; m&#43;&#43;)
stu->score[m] &#61; 0;
return 1;
}
void write(struct achievement *stu)
{
int i;
printf(“name :%s\n”, stu->name);
printf(“number :%s\n”, stu->number);
printf(“score :”);
for (i &#61; 0; i <&#61; 4; i&#43;&#43;)
printf(“%d”, stu->score[i]);
}
void main()
{
int i, n;
printf(“please input the students’ achievement:\n”);
for (n &#61; 0; n {
read(stu &#43; n);
printf(“please input the next’s:\n”);
}
for (i &#61; 0; i <&#61; n; i&#43;&#43;)
write(stu &#43; i);
}