473,395 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Question about fscanf ..

Hiho,

I have an ASCII-File with data from a simulation programm. It lookslike
this:

2.500000E+0026.911733E+0022.950929E+0054.746349E+0 040.000000E+0000.000000E+0
00
2.590362E+0023.806547E+0023.377923E+0057.040307E+0 040.000000E+0000.000000E+0
00
-1.000000E+000-1.000000E+000-1.000000E+000-1.000000E+0000.000000E+0000.00000
0E+000
2.530572E+0022.145215E+0021.750804E+0053.285819E+0 030.000000E+0000.000000E+0
00
2.537223E+0026.500754E+0024.166493E+0056.221317E+0 040.000000E+0000.000000E+0
00
-1.000000E+000-1.000000E+000-1.000000E+000-1.000000E+0000.000000E+0000.00000
0E+000
2.547310E+0025.723339E+0023.675294E+0055.031395E+0 040.000000E+0000.000000E+0
00
2.549374E+0025.902411E+0023.681309E+0056.965566E+0 040.000000E+0000.000000E+0
00
2.533486E+0026.700119E+0023.686952E+0055.628433E+0 040.000000E+0000.000000E+0
00
2.537227E+0026.500726E+0024.168410E+0056.231714E+0 040.000000E+0000.000000E+0
00
2.600828E+0023.426328E+0023.277678E+0055.456118E+0 040.000000E+0000.000000E+0
00
2.601910E+0023.427085E+0022.484092E+0053.851131E+0 040.000000E+0000.000000E+0
00
-1.000000E+000-1.000000E+000-1.000000E+000-1.000000E+0000.000000E+0000.00000
0E+000
2.548592E+0025.911483E+0023.347479E+0054.669881E+0 040.000000E+0000.000000E+0
00
2.548747E+0025.907943E+0023.208793E+0054.656371E+0 040.000000E+0000.000000E+0
00

You can see that there are 6 columns. Im interested in the second column.
But I dont know how to access this column. I tried several options with
fscanf. But nothing worked. Anybody knows how to do it?

I tried something like that:

fscanf(temp, "%f %f %f %f %f %f", var, var 2 .... ); Tried the Options
E and so on ..

Thx for help.

Greetings Marc
Jul 22 '05 #1
2 1533
Marc Reclaire wrote:
Hiho,

I have an ASCII-File with data from a simulation programm. It lookslike
this:

2.500000E+0026.911733E+0022.950929E+0054.746349E+0 040.000000E+0000.000000E+0
00
2.590362E+0023.806547E+0023.377923E+0057.040307E+0 040.000000E+0000.000000E+0
00 <snip/>
You can see that there are 6 columns. Im interested in the second column.
But I dont know how to access this column. I tried several options with
fscanf. But nothing worked. Anybody knows how to do it?

I tried something like that:

fscanf(temp, "%f %f %f %f %f %f", var, var 2 .... ); Tried the Options
E and so on ..


Are you parsing a tr0?

In what way did fscanf not work? Did you get a compile-time error, or a
fatal, run-time error, or did the correct values just not end up in the
variables? What are the types of var and var2?

My guess is that var and var2 are single-precision, and that your floats
just aren't big enough. <insert> witty crack about genetics. </> If
so, try declaring them as doubles.

-Jeff

Jul 22 '05 #2
Marc Reclaire wrote:


You can see that there are 6 columns. Im interested in the second column.
But I dont know how to access this column.
Read all 6 and use only the 2-nd
I tried several options with
fscanf. But nothing worked. Anybody knows how to do it?

I tried something like that:

fscanf(temp, "%f %f %f %f %f %f", var, var 2 .... ); Tried the Options
E and so on ..


If you want us to help you sort out your errors you have to post real
code.
--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Fallon | last post by:
If someone could help it would be greatly appreciated. I am trying to write a simple program to read in elements from an input file formatted as follows: 3 4 81 5 6
4
by: Cal Lidderdale | last post by:
My input line is i1,i2,i3,i4,i5,i6,i7,i8^,...i596,597, ... 14101,14102...NL/CR very long line of data - I only want the first 8 items and the delimiter between 8 & 9 is a carrot "^". The line...
5
by: No Such Luck | last post by:
Hi All: I have a loop in which I scan an entire file for a particular string ("Error:"). However, I don't know the specifics of testing for the EOF. while (1) /* This should be while (!EOF) or...
1
by: siliconwafer | last post by:
Hi All, here is one code: int main() { FILE*fp; unsigned long a; fp = fopen("my_file.txt","w+"); a = 24; fprintf(fp,"%ld",a); while(fscanf(fp,"%ld",&a) == 1) {
2
by: Gary Baydo | last post by:
The following program illustrates a question I have about fscanf() behavior: #include <stdio.h> #include <stdlib.h> #include <string.h> int main(void) { FILE *testfile; char s1 =...
2
by: yezi | last post by:
Hi, ALl: The following code is to canculate 2 vector distance. Suppose the vectore is stored in some txt file like -1 0.34 0 0.045 1 0.98 1 0.01
7
by: ehui928 | last post by:
I use the following program to read some strings from an inupt file, and print them on the standard output. But the last string in the input file always printed twice, what is the reason and how...
6
by: haloman | last post by:
Why does: char *myString = (char *) malloc(WORDLIMIT*sizeof(char)); fscanf(openFile, "%s", myString) != EOF; work yet char *myString = (char *) malloc(WORDLIMIT*sizeof(char));...
10
by: Roman Zeilinger | last post by:
Hi I have a beginner question concerning fscanf. First I had a text file which just contained some hex numbers: 0C100012 0C100012 ....
8
by: Fred | last post by:
I've got following program encapsuled fscanf, however, it doesn't work. I'm sure that the content format in "a.txt" is OK, the content would be correctly read if using fscanf directly, what's...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.