GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 26-Oct-2003, 02:54
jmenendezr jmenendezr is offline
New Member
 
Join Date: Oct 2003
Posts: 3
jmenendezr is an unknown quantity at this point

Reading from file


Hi, im trying to read data from a file to an array. The file is like this:

0 1 2
1 2 3
2 3 4
.
.
10 11 12

i have dfined this variables:
CPP / C++ / C Code:
ifstream inFile("file.txt");
... //error handling

int Data[11][2];
int i=0;

i use this loop:

while (inFile >> Data[i][0] >> Data[i][1] >> Data[i][2])
{
  cout << i << ' ' << Data[i][0] << Data[i][1] << Data[i][2] << '\n';
  i++;
}

but when i run the program, when the index i reaches 9 it shows a classic windows dialog stating "This program ... invalid operation ....close". When i define the array with 12 elements it works but i get extra elements like 12 345637373 0 534327437
(probably other memory data).

Because i will use this array for some mathematical processing i need to have only the number of registers exactly, i mean if the file has 11 registers i need an array with 11 rows. This is because i don't know the number of registers a priori so i need to calculate the size of the array while processing. Can you help me with this? Thx in advance
  #2  
Old 26-Feb-2006, 13:13
TurboPT's Avatar
TurboPT TurboPT is offline
Regular Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 956
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: Reading from file


I know this is old, but the second dimension value of the array you are trying to read is 1 too short. You needed Data[11][3] to properly read your example data.
  #3  
Old 26-Feb-2006, 16:00
TreyAU21's Avatar
TreyAU21 TreyAU21 is offline
Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 116
TreyAU21 has a spectacular aura aboutTreyAU21 has a spectacular aura about

Re: Reading from file


Whoa... pulling one out of the archive there aren't ya
__________________
If practice makes perfect and nobody's perfect... why practice?

Homepage: http://www.treywhite.com
Blog: http://www.treywhite.com/blog.php
Web Design Company: http://www.ewebproductions.com
 
 

Recent GIDBlogFlickr uploads of IA pictures by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Limited file size.... lament Apache Web Server Forum 2 31-May-2004 13:35
writing into file prob belludandy C Programming Language 0 15-Nov-2003 19:25
How to offer .tar.gz file downloads? JdS MySQL / PHP Forum 6 14-Sep-2003 17:30
How to search a huge text file for data? JdS MySQL / PHP Forum 7 27-May-2003 09:27
How Do i get php to find out the file type of a file for me? viperman95833 MySQL / PHP Forum 2 08-Mar-2003 09:48

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 18:38.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.