#include "stdio.h"
#define NUM 3
#define L 100
struct mem
{
char name[20];
char score3[5];
char score4[5];
char score5[5];
}man[NUM];
main()
{
int i;
char ch[100];
FILE *fp;
for(i=0;i<NUM;i++)
{
printf("input name:\n");
scanf("%s",man[i].name);
printf("input score:\n");
scanf("%s",man[i].score1);
printf("input score:\n");
scanf("%s",man[i].score2);
printf("input score:\n");
scanf("%s",man[i].score3);
printf("input score:\n");
scanf("%s",man[i].score4);
printf("input score:\n");
scanf("%s",man[i].score5);
}
printf("name\tscore1\tscore2\tscore3\tscore4\tscore5\n\n");
for(i=0;i<NUM;i++)
{
printf("%s\t%s\t%s\t%s\t%s\t%s\n",man[i].name,man[i].score1,man[i].score2,man[i].score3,man[i].score4,man[i].score5);
}
fp = fopen("/home/wanwj/sdve/testc.txt","w");
if(!fp)
{
printf("测试文件/home/wanwj/sdve/testc.txt打开错误!");
return;
}
for(i=0;i<NUM;i++)
{
sprintf(ch,"%-20.20s%5.5s%5.5s%5.5s%5.5s%5.5s",man[i].name,man[i].score1,man[i].score2,man[i].score3,man[i].score4,man[i].sc
ore5);
fputs( ch, fp );
}
fclose(fp);
}