![]() |
|
|||||||
|
|
Thread Tools | Search this Thread | Rate Thread |
|
#1
|
|||
|
|||
Having trouble reading in floats from a text file into a 2-dim arrayHello,
I have a text file that contains data similar to this table -http://www.itl.nist.gov/div898/handbook/eda/section3/eda3673.htm#ONE-05-1-10 I've stripped off any leading whitespaces, so it is just a continuous stream of decimal numbers separated by blank characters. I want to be able to pass in two numbers to a function, use those two numbers as arguments to the array, and return a float value. To do this, I wrote a function that reads the whole string of numbers in, and assigns them as row and column locations to a two dimensional array. CPP / C++ / C Code:
This works perfectly except for one thing - it converts all the floats to ints! This is a sample line of data; 161.448 199.500 215.707 224.583 230.162 233.986 236.768 238.882 240.543 This is what I get for output; 161 200 216 225 230 234 237 239 241 All my variables are floats, the array is a float....I don't get it. The '.' isn't a delimiter in this case, so I don't think that's the problem. Besides, it's not just dropping the decimal, it's actually rounding up or down to an int. I thought this would be a snap, but it's driving me nuts Any help would be tremendously appreciated! Thanks! |
|
#2
|
|||
|
|||
|
I found this http://h30097.www3.hp.com/cplus/clu006.htm but I am not sure how to set up the syntax right. It looks like it could read in just floats with an istream, but not sure how to work this into my code.
http://www.cs.niu.edu/~abyrnes/csci241/iostream.htm |
|
#3
|
|||
|
|||
Re: Having trouble reading in floats from a text file into a 2-dim arrayHi ,
Following code read the data with decimal points. Thanks Chandana CPP / C++ / C Code:
Last edited by admin : 23-Jun-2006 at 18:37.
Reason: Please insert your C code between [cpp] & [/cpp] tags
|
|
#4
|
||||
|
||||
Re: Having trouble reading in floats from a text file into a 2-dim arrayGuideline #1 -- how to post code
Guideline #2 -- what does the code do wrong, what does the file look like -- basically a detailed explanation of the problem you're having. Any answer to what you gave is a complete guess. __________________
Age is unimportant -- except in cheese |
Recent GIDBlog
Developing GUIs with wxPython (Part 3) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Airport Log program using 3D linked List : problem reading from file | batrsau | C Programming Language | 11 | 29-Feb-2008 07:44 |
| CD Burner Help - Power Calibration Error.... | JonBoy420 | Computer Hardware Forum | 110 | 05-Feb-2008 18:34 |
| CD burner wont burn!! | robertli55 | Computer Hardware Forum | 1 | 18-Jun-2004 10:53 |
| Yet another CD burner problem: Lite-On LSC-24082K | Erwin | Computer Hardware Forum | 1 | 22-May-2004 11:28 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The