GIDForums  

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

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 20-Jul-2004, 08:00
gwk gwk is offline
Awaiting Email Confirmation
 
Join Date: Jun 2004
Posts: 8
gwk is on a distinguished road

2 D char Array


Hi All,
I want to rephrase my earlier question.
Actually what I am looking for is 2 dimensional char array. OR set of char arrays where the names of each array is ending the number of the array. i.e the ith array would be the ith row if we make it through 2 dimensional array.
The point is that the ith number is not determined beforehand. It depends on the iteration and it could be any number.

I tried it with 2 dimensional array but it doesnt work.
Here is my code
Quote:
CPP / C++ / C Code:
char 2Dtable[1000][1000];

//I try to copy the line contents array in 5th row of the 2Dtable which is a 2 D array itself

strcpy( 2Dtable[5][], Linecontents ); 

// I am not including the while loop stuff that finally stops the iteration.

When I run this code it gives the following error:
Quote:
error C2059: syntax error : ']'

Any suggestion for both options?
Last edited by dsmith : 20-Jul-2004 at 09:29.
  #2  
Old 20-Jul-2004, 09:41
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Hi gwk. Try using:
CPP / C++ / C Code:
strcpy( 2Dtable[5], Linecontents ); 

I am not sure if this answers your full question or not to be honest. Your original question was asking if you could use dynamic variable names. The answer is no. So, if the 2-d char array can be used to solve your problem, then you are in good shape. If not, you may need to set up your own variable structure:

CPP / C++ / C Code:
typedef struct{
  char varname[100];
  char value[100];
}dname;

I may not be clear on your full question, if this doesn't help, please post again and let us know.

Thanks.
  #3  
Old 20-Jul-2004, 11:07
aaroncohn's Avatar
aaroncohn aaroncohn is offline
Regular Member
 
Join Date: Feb 2004
Location: Bay Area, CA.
Posts: 564
aaroncohn is a jewel in the roughaaroncohn is a jewel in the roughaaroncohn is a jewel in the rough
Why on earth would need to use dynamic variable names in such a way to defeat the entire purpose of using arrays in the first place? I don't see why you would want to create a bunch of variables of the same type that have the same name except for a number on the end, when that's exactly what an array does!
__________________
-Aaron
  #4  
Old 20-Jul-2004, 14:40
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Quote:
Originally Posted by aaroncohn
Why on earth would need to use dynamic variable names in such a way to defeat the entire purpose of using arrays in the first place? I don't see why you would want to create a bunch of variables of the same type that have the same name except for a number on the end, when that's exactly what an array does!

Without knowing exactly what gwk is doing, I agree with your statement Aaron. However, there may be something else that he is trying to do that I don't see, so I wanted to give him this option as well. You could actually turn that into a pretty efficient class that would allow user declared variables. I have done similar things before.
 
 

Recent GIDBlogPython ebook 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
3D array dynamic memory allocation cjwatchdog C Programming Language 3 20-Feb-2004 16:27
throwing an struct(with an array) through a function knakworstje C Programming Language 5 15-Feb-2004 17:20
(read/write file) newbie need help plz momotx C Programming Language 6 28-Jan-2004 14:40
convert long to pointer to char realpopeye C++ Forum 2 26-Sep-2003 11:22

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

All times are GMT -6. The time now is 01:13.


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