Reading variable size text data sets.... 
Author Message
 Reading variable size text data sets....

I'm hoping to find a short piece of code that reads
data sets that are simple text columns of numbers,
but can be variable number of columns and with
variable delimneters.  For example, this data set...

1.0, 0.234
2.1, 3.224
3.0, 2.221, 3.223
3.9  5.21
5.2  2.11  3.09
6.1, 4.221

where the destination is a simple array:

float fdata[MAX_COLUMNS+1][MAX_ROWS+1];

We can restrict the delimeters to comma, tab, and space.
I can worry about filling in missing values.  I do
want ansi portability.  Is there a site (ftp or other)
with standard code that would be useful ?

Thanks for helping me not reinvent this wheel.


   Laboratory of Molecular Biophysics



Sun, 11 Feb 1996 01:16:11 GMT  
 Reading variable size text data sets....
( dave duling ) writes:

Quote:
> I'm hoping to find a short piece of code that reads
> data sets that are simple text columns of numbers,
> but can be variable number of columns and with
> variable delimneters.  For example, this data set...

> 1.0, 0.234
> 2.1, 3.224
> 3.0, 2.221, 3.223
> 3.9  5.21
> 5.2  2.11  3.09
> 6.1, 4.221

> where the destination is a simple array:

> float fdata[MAX_COLUMNS+1][MAX_ROWS+1];

I recommend using "fgets" to get each line, and use "strtok" with
separator ", \n\t" to parse the line.  Of course, you may wish to
use one of the re-entrant implementations of "strtok" (such as
"xstrtok") if you are using "strtok" somewhere else in your
program.

-- Andrew Choi



Mon, 12 Feb 1996 02:19:15 GMT  
 Reading variable size text data sets....

Quote:
>( dave duling ) writes:
>> I'm hoping to find a short piece of code that reads
>> data sets that are simple text columns of numbers,
>> but can be variable number of columns and with
>> variable delimneters.  For example, this data set...

>> 1.0, 0.234
>> 2.1, 3.224
>> 3.0, 2.221, 3.223
>> 3.9  5.21
>> 5.2  2.11  3.09
>> 6.1, 4.221

>> where the destination is a simple array:

>> float fdata[MAX_COLUMNS+1][MAX_ROWS+1];

>I recommend using "fgets" to get each line, and use "strtok" with
>separator ", \n\t" to parse the line.  Of course, you may wish to
>use one of the re-entrant implementations of "strtok" (such as
>"xstrtok") if you are using "strtok" somewhere else in your
>program.

sscanf() after fgets() is all that's needed, provided you know how to use
some of the features of the format string. In order to make repeated use of
sscanf() on the same line, %n has to be used, besides the obvious %f%c.

Dan
--
Dan Pop
Tel:   +41.22.767.2335

Mail:  CERN - PPE, Bat. 21 1-023, CH-1211 Geneve 23, Switzerland



Mon, 12 Feb 1996 04:50:08 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Passing variable-size data between trampolines

2. fscanf- reading from a file to a variable size array

3. Setting Maximum Text size for textbox

4. Set Label/Static Text font size

5. CListCtrl - Setting Column Width based on text size

6. : How to set text size

7. Help - I need to set variable A = value held in variable named in variable B

8. size ofthe text iam reading

9. How to read arbitrary sized data

10. Read non separated variables from a text file with fscanf

11. Read a text file into variables

12. Help w/reading data set separated by space

 

 
Powered by phpBB® Forum Software