【发布时间】:2016-09-10 11:16:39
【问题描述】:
我是 C 编程新手。我正在处理具有以下格式的文本文件
1 2009 詹姆斯史密斯 2 18
2 2010 年鲍勃·戴维斯 5 18
3 2010 艾伦汤姆森 15 26
4 2010 布拉德海耶 15 26
我想要做的是读取每一行并以有意义的方式打印到控制台
詹姆斯·史密斯于 2009 年首次亮相,年收入 200 万。他一生赚了1800万,平均每年xyzM
然后
最高收入者:?
平均收入:?
玩家总数:
这是我目前所拥有的:
#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include <stdlib.h>
typedef char *string;
int main() {
int i = 0, line = 5;
char ch[100];
string array[4];
FILE *myfile;
myfile = fopen("C:/Data/Players.txt","r");
if (myfile== NULL)
{
printf("File Does Not Exist \n");
return 1;
}
while(line--)
{
fscanf(myfile,"%s",&ch[i]);
printf("\n%s", &ch[i]);
array[0] = array[i];
i++;
if(i=5)
{
printf("Yes");
}
}
fclose(myfile);
return 0;
}
【问题讨论】:
-
几乎所有的初学者书籍或教程都会通过你了解
scanf。
标签: c arrays dynamic-programming