#include <stdio.h>
#include <stdlib.h>
#define LIMIT 30
int main(void)
{
FILE *fp;
char str[LIMIT];
int value;
int total;
char *buf;
int i;
if((fp = fopen("test.txt","r")) == NULL)
{
perror("error to open the file\n");
exit(1);
}
while(fgets(str,LIMIT,fp) != NULL && str[0] != '\n')
{
for(total = 0,buf = str,i = 0;sscanf(buf,"%d",&value) == 1;)
{
total += value;
i++;
while(*buf != ' ' && *buf != '\n')
++buf;
buf = buf + 1;
}
printf("the family the average is %5.2f:%s",(float)total / i,str);
}
fclose(fp);
system("pause");
return 0;
}
草稿
最新推荐文章于 2024-07-15 17:05:45 发布