计算Float值并存储在文件中的不同变量中 [英] Count Float values and store in different variables from file
问题描述
我想从文件读取浮点值(值的数量未知)&在我的基于MFC对话的应用程序中分配给不同的变量。我做了很多尝试,但它只从值中检索一个值!!
如何做到这一点?
首先尝试ony检索拳头值
fscanf(fp,%0.20f \ t,& t21);
fscanf(fp,%0.20f \ t,& t31);
t21 = o * 1e12;
t31 = o * 1e12 ;;
fclose(fp);
另一个成功尝试检索最后一个值(我认为)!!
while ((i = fscanf(fp, %f,& o))!= EOF)
{
size + = i;
t21 = o * 1e12;
t31 = o * 1e12;
}
fclose(fp);
如何做到这一点?请给出解决方案!
提前致谢!
在我看来,问题是数据strcutre,因为我没有看到任何数据结构来保存文件中的读取值。请使用链接列表。它可能有帮助
而((i = fscanf(fp, %f,& o))!= EOF)
{
size + = i;
t21 = o * 1e12;
t31 = o * 1e12;
}
fclose(fp);
在上述情况下声明表达循环后的整数变量
就像这样
while((i = fscanf(fp,& quot;%f& quot;,& amp; o) ))!= EOF)
{int n = 0;
t21 = o * 1e12;
t31 = o * 1e12;
n ++;
}
/ *这里通过取n值你可以计算通过
循环传递多少个浮点变量根据你可以计算内存的值用于该操作。 * /
I wanted to read float values from file(count of values is not known)& assign to different variables in my MFC dialogue based application.I do s many try,but it retrieves only one value from value!!
How to do that?
First Try ony retrieves fist value
fscanf(fp,"%0.20f\t",&t21); fscanf(fp,"%0.20f\t",&t31); t21=o*1e12; t31=o*1e12;; fclose(fp);
Another success try retrieves last value(I think)!!
while ((i=fscanf(fp,"%f",&o))!=EOF)
{
size+=i;
t21=o*1e12;
t31=o*1e12;
}
fclose(fp);
How to do that?please give solution!
Thanks in advance!
It seems to me that the problem is the data strcutre as i don't see any data strucutre to hold read values from file. Please use linklist. It might help
while ((i=fscanf(fp,"%f",&o))!=EOF) { size+=i; t21=o*1e12; t31=o*1e12; } fclose(fp);
In above case declare an Integer variable after the expression of loop
just like this
while ((i=fscanf(fp,"%f",&o))!=EOF)
{ int n = 0;
t21=o*1e12;
t31=o*1e12;
n++;
}
/* Here By taking n value you can count how many float variables passed through the
loop according to that value you can calculate the memory used for that operation. */
这篇关于计算Float值并存储在文件中的不同变量中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!