Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | James Kuyper <jameskuyper@verizon.net> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: new question about data file |
| Date | 2015-06-08 11:43 -0400 |
| Organization | Self |
| Message-ID | <5575B822.2050601@verizon.net> (permalink) |
| References | <ml3qfu$6mv$1@dont-email.me> |
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.
Back to comp.lang.c | Previous | Next — Previous in thread | Find similar | Unroll thread
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
csiph-web