array of strings?

R

Robert

Hi,

Is there some way of using an array of strings? Like in basic?
I know you have to create an array of chars so i think it has to
be an 2d array or something...

Really stuck here... Thanks in advance,

Robert
 
I

Irrwahn Grausewitz

Robert said:
Hi,

Is there some way of using an array of strings? Like in basic?
I know you have to create an array of chars so i think it has to
be an 2d array or something...

Your problem is currently addressed in todays thread starting off
with message [email protected],
Subject: Please help! char* problems!
Really stuck here... Thanks in advance,

Robert

Regards

Irrwahn
 
J

Jirka Klaue

Robert said:
Is there some way of using an array of strings? Like in basic?
I know you have to create an array of chars so i think it has to
be an 2d array or something...

char *arofstr[] = {"foo", "bar", "baz"};

Jirka
 
L

Lew Pitcher

Hi,

Is there some way of using an array of strings? Like in basic?
I know you have to create an array of chars so i think it has to
be an 2d array or something...

There are at least a couple of ways to define/use an "array of strings".

First off, strings (in C) are arrays of char, with contents that are terminated
by a \0 char.

Thus
char String[10] = "string";
is a string, as is
char *String = "string";
(actually, in this case, the String variable is a pointer, but it points to an
array of char, terminated with a \0, so it points to a "string");

So, how do we get an array of strings? We get arrays of arrays of chars, or
arrays of pointers to chars.

Thus
char StringArray[3][10] = {"string1", "string2", "string3"};
is an array of strings, as is
char *StringArray[3] = {"string1", "string2", "string3"};

Does that help?
--
Lew Pitcher
IT Consultant, Enterprise Technology Solutions
Toronto Dominion Bank Financial Group

(Opinions expressed are my own, not my employers')
 
R

Robert

Robert said:
Hi,

Is there some way of using an array of strings? Like in basic?
I know you have to create an array of chars so i think it has to
be an 2d array or something...

Really stuck here... Thanks in advance,

Robert

Alright, because i didn't was very clear (srry for that) i'll
try again... I am used to basic so here is an example of what i
mean in basic...

dim somestring(1 to 10) as string

I maybe need to resize both the array and the actual string
in runtime so can someone please give me an example of that?

btw i looked in that other topic but didn't find where i was
searching for...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,079
Messages
2,570,574
Members
47,206
Latest member
Zenden

Latest Threads

Top