用c语言编程 高手请进,简单程序出错,高手请进

你的失误:

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 = 0; i < 5; i++)

{

if (scanf(“%d”, &num) == 1)

stu->score[i] = num;

else

break;

}

for (m = i; m <= 4; m++)

stu->score[m] = 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 = 0; i <= 4; i++)

printf(“%d”, stu->score[i]);

}

void main()

{

int i, n;

printf(“please input the students’ achievement:\n”);

for (n = 0; n < total; n++)

{

read(stu + n);

printf(“please input the next’s:\n”);

}

for (i = 0; i <= n; i++)

write(stu + i);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值