Click here to Skip to main content
15,897,718 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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)!!
C++
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!
Posted
Comments
Richard MacCutchan 29-Jun-13 5:43am    
Step through the code with your debugger to see what is happening. It's impossible to guess from the above as we cannot see the input data.

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
 
Share this answer
 
C#
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. */
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900