![]() |
|
|||||||
|
|
Thread Tools | Search this Thread | Rate Thread |
|
#1
|
|||
|
|||
How to read unknown total of int data from text file to a 2-dim array in C or C++?I want to create a function read data of type int from a text file and stores them in a 2-dimensional array. But the number of the data in the text file is unknown during the program execution. Therefore the size of the array is also unknown.
I have problems in reading the correct data value of type int and stores them in the array. I also can't determine the correct total of columns and rows for the array. My data in the text file looks something like this: 1111111111111111111 1000101010101010101 1010101010101011111 1111111111111111111 1011110000111111111 1111111111111111111 My coding is as below: CPP / C++ / C Code:
Does anyone knows the easiest solution to this? Please give me any complete source code examples for reading data of type int in text file and determining the total of rows and columns? Later, I need to scan each row of data for 0s and stores them in text file.then I access the text file to normalize all 0s by rows. Therefore I need to save the information about the location of the 0s(which rows and columns).After the normalization,I need to replace the 0s in the later text file with the new value at the correct location. How to save the location value(rows and pixels) and corresponds them with their new normalized value? Thanks in advance. Last edited by LuciWiz : 09-Sep-2005 at 00:07.
Reason: Please insert your C code between [c] & [/c] tags
|
|
#2
|
|||
|
|||
|
I'd just use this, but you seem to be programming in C so this might not be an acceptable solution:
Code:
|
|
#3
|
||||
|
||||
|
First problem I see can be solved by reading this thread, 2nd post. It will help make sure you are reading the correct amount of data.
Second, the tutorial on code formatting is important. If your code is hard to read, the tendancy is to move to the next post. Also, the Guidelines are helpful for getting the code tags right. Two possibilities: 1) create a 2D buffer of ints that can hold a maximum number of rows/columns that makes sense for your problem. I.e. creater a matrix of [100][100] if you know for sure there will never be that many values in your file. I see this is the solution you've started with. It is the easiest. 2) the hard way is to allocate a pointer to an array buffer. You will be dealing with pointers and pointers to pointers in this case, as well as allocating memory. If that's a scary concept, continue as you are. But if pointers are OK, let us know and we can help you with that solution. __________________
Cow: You're a lawyer too? Mooseblood (mosquito): Ma'am, I was already a bloodsucking parasite. All I needed was a briefcase! |
Recent GIDBlog
Flickr uploads of IA pictures 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 |
| [Include] Doubly-linked List | dsmith | C Programming Language | 6 | 14-Apr-2006 13:12 |
| 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