Advertisement

File Input

Started by July 10, 2000 07:00 AM
2 comments, last by Verminaard 24 years, 6 months ago
This is very strange: I''m inputing and outputting floats to a file with spaces in between them like this: fscanf(in, "%f ", &ts1.T1[0].v.x); fprintf(out, "%f ", ts1.T1[0].v.x); And this works fine. (forget about the weird float, don''t ask). Then when I repeat the like this: fprintf(out, "%f ", ts1.T1[1].v.x); fprintf(out, "%f ", ts1.T1[1].v.x); fprintf(out, "%f ", ts1.T1[1].v.x); it works fine. But the problem is when I do this: for(int loop=0; loop<48; loop++) { fprintf(out, "%f ", ts1.T1[loop].v.x); } All this does is outputs the last float. What is with this? Any help would be appreciated.
-------------I am a Juggalo.
quote:
fprintf(out, "%f ", ts1.T1[1].v.x);
fprintf(out, "%f ", ts1.T1[1].v.x);
fprintf(out, "%f ", ts1.T1[1].v.x);


You do see that you're writing the same float three times there? And when your reading it, you read the same float two times.

quote:
All this does is outputs the last float. What is with this? Any help would be appreciated.


Maybe all the floats are the same?

- Muzzafarath

Mad House Software
The Field Marshals

Edited by - Muzzafarath on July 10, 2000 12:40:32 PM

Edited by - Muzzafarath on July 10, 2000 12:43:52 PM
I'm reminded of the day my daughter came in, looked over my shoulder at some Perl 4 code, and said, "What is that, swearing?" - Larry Wall
Advertisement
You for() loop should work fine. Make sure (1) you are closing the file when you''re done, and (2) you''re not clobbering the ''loop'' variable somehow (perhaps an array declared before it that you are over-populating; I''ve done that before..).

// CHRIS
// CHRIS [win32mfc]
Well, I can''t figure it out. Here''s the exact code:

FILE *out;
out = fopen("oin1.map", "wb");

for(int loop=0; loop<5; loop++);
{
fprintf(out, "%f ", ts1.T1[loop].v.x);
fprintf(out, "%f ", ts1.T1[loop].v.y);
fprintf(out, "%f ", ts1.T1[loop].v.z);
fprintf(out, "%f ", ts1.T1[loop].tu);
fprintf(out, "%f ", ts1.T1[loop].tv);
}

fclose(out);

The resulting file only has 5 numbers, and the really weird thing is, is that the five numbers are that of ts1.T1[5] !

This is very, very strange and I''ve been stuck on it for quite a while.
-------------I am a Juggalo.

This topic is closed to new replies.

Advertisement