我是C新手,现在一直在尝试做这件事。从C文本文件中逐行读取整数并将它们存储在一个数组中
我需要读取从具有文本文件中的整数值:
G = 10
P = 5
盖尔:1,2,3,4
价格:4,3,5,6.6
需要挑出Gayle和Price值并将它们存储在2个独立的数组中,并将G和P值存储在2个单独的变量中。
到目前为止,我已经做了:
FILE* file = fopen(abc.txt, "r");
//for gayle values
int g_array[100];
int i=0;
int gayle_val;
while(fscanf("%d", &gayle_val)==1)
{
g_array[i]=gayle_val;
}
//for price values
int p_array[100];
int i=0;
int price_val;
while(fscanf("%d", &price_val)==1)
{
p_array[i]=price_val;
}
//for G and P values
如何结合搜索的4线使得读取由线完成并相应地进行存储的值?
非常感谢你提前!
价格样本包括6.6。转换为'int'? – BLUEPIXY