Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #63061 > unrolled thread

new question about data file

Started bybilsch01 <king621@comcast.net>
First post2015-06-08 03:25 -0700
Last post2015-06-08 11:43 -0400
Articles 2 — 2 participants

Back to article view | Back to comp.lang.c


Contents

  new question about data file bilsch01 <king621@comcast.net> - 2015-06-08 03:25 -0700
    Re: new question about data file James Kuyper <jameskuyper@verizon.net> - 2015-06-08 11:43 -0400

#63061 — new question about data file

Frombilsch01 <king621@comcast.net>
Date2015-06-08 03:25 -0700
Subjectnew question about data file
Message-ID<ml3qfu$6mv$1@dont-email.me>
Taking into account the responses to my previous post (counting bytes) 
to the extent that I understand those responses I need more information 
to read my data file.  I am reading with the same machine and OS that I 
wrote the file with.  This is how I wrote the data:

float w1,w2,w3,k1;
int xf,yf,xof,yof,xm,ym,delay,glength;
fprintf(fp,"%f%f%f%f%i%i%i%i%i%i%i%i",w1,w2,w3,k1,xf,yf,xof,yof,xm,ym,delay,glength);

Here is how I'm trying to read it back and print it:

fscanf(fp,"%f%f%f%f%i%i%i%i%i%i%i%i",&w1,&w2,&w3,&k1,&xf,&yf,&xof,&yof,&xm,&ym,&delay,&glength);
printf("%f    %f    %f    %f    %i    %i    %i    %i    %i    %i    %i 
%i\n",w1,w2,w3,k1,xf,yf,xof,yof,xm,ym,delay,glength);

The floats read and print correctly but the ints are all wrong.  Can 
someone tell me the correct way to do the fscanf and printf statements 
so I get back the data that I wrote?

TIA.    Bill S.

[toc] | [next] | [standalone]


#63079

FromJames Kuyper <jameskuyper@verizon.net>
Date2015-06-08 11:43 -0400
Message-ID<5575B822.2050601@verizon.net>
In reply to#63061
On 06/08/2015 06:25 AM, bilsch01 wrote:
> Taking into account the responses to my previous post (counting bytes) 
> to the extent that I understand those responses I need more information 
> to read my data file.  I am reading with the same machine and OS that I 
> wrote the file with.  This is how I wrote the data:
> 
> float w1,w2,w3,k1;
> int xf,yf,xof,yof,xm,ym,delay,glength;
> fprintf(fp,"%f%f%f%f%i%i%i%i%i%i%i%i",w1,w2,w3,k1,xf,yf,xof,yof,xm,ym,delay,glength);
> 
> Here is how I'm trying to read it back and print it:
> 
> fscanf(fp,"%f%f%f%f%i%i%i%i%i%i%i%i",&w1,&w2,&w3,&k1,&xf,&yf,&xof,&yof,&xm,&ym,&delay,&glength);
> printf("%f    %f    %f    %f    %i    %i    %i    %i    %i    %i    %i 
> %i\n",w1,w2,w3,k1,xf,yf,xof,yof,xm,ym,delay,glength);
> 
> The floats read and print correctly but the ints are all wrong.  Can 
> someone tell me the correct way to do the fscanf and printf statements 
> so I get back the data that I wrote?

Here's what I recommend:
1) Give us the precise values of w1, w2, w3, k1, xf, yf, xof, yof, xm,
ym, delay, and glength had at the time you printed them out.
2) Show us what the resulting file looked like. Since you're using
formatted I/O (fprintf()) rather than unformatted I/O (fwrite()), the
result will be ordinary text, so it can easily be displayed.
3) Looking at the file, try to figure out how fscanf() should figure out
where each number starts and ends.

Step 3 will either produce a revelation, or a lot of questions. We'll be
glad to answer those questions. There's several different solutions to
your problem, but it will be best to discuss them after you understand
better what the problem is.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.c


csiph-web