By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,305 Members | 1,764 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,305 IT Pros & Developers. It's quick & easy.

File Handling

P: 2
Hi I am reading a text file containing 2d array and I have to use the first column for my conditions.
Both columns are having integers values.
How can I handle the file?
Reply with sample code if poss.
Jun 12 '07 #1
Share this Question
Share on Google+
3 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
Read the file into the address of element [0][0].

Arrays in C and C++ are really one dinensional.

That is:
Expand|Select|Wrap|Line Numbers
  1. int arr[8] = {1,2,3,4,5,6,7,8}
  2.  
has a memory layout of

1 2 3 4 5 6 7 8

This array:
Expand|Select|Wrap|Line Numbers
  1. int arr[4][2] = {1,2,3,4,5,6,7,8}
  2.  
has a memory layout of

1 2 3 4 5 6 7 8


So, you might as well read into &arr[0][0] and then go ahead and use your array as a 2D array.
Jun 12 '07 #2

Savage
Expert 100+
P: 1,764
Read the file into the address of element [0][0].

Arrays in C and C++ are really one dinensional.

That is:
Expand|Select|Wrap|Line Numbers
  1. int arr[8] = {1,2,3,4,5,6,7,8}
  2.  
has a memory layout of

1 2 3 4 5 6 7 8

This array:
Expand|Select|Wrap|Line Numbers
  1. int arr[4][2] = {1,2,3,4,5,6,7,8}
  2.  
has a memory layout of

1 2 3 4 5 6 7 8


So, you might as well read into &arr[0][0] and then go ahead and use your array as a 2D array.
weaknessforcats shame on you,this is article section..

Savage
Jun 12 '07 #3

weaknessforcats
Expert Mod 5K+
P: 9,197
weaknessforcats shame on you,this is article section..
I didn't notice that. I'll move the thread.
Jun 12 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.