473,394 Members | 1,770 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

array of strings?

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
Nov 13 '05 #1
5 39413
Robert <R.****@hetnet.nl> wrote:
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 3f********@clarion.carno.net.au,
Subject: Please help! char* problems!

Really stuck here... Thanks in advance,

Robert


Regards

Irrwahn
--
Close your eyes and press escape three times.
Nov 13 '05 #2
Robert wrote:
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

Nov 13 '05 #3
Robert wrote:
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...
Nov 13 '05 #4
On Thu, 11 Sep 2003 17:41:38 +0200, Robert <R.****@hetnet.nl> wrote:
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')
Nov 13 '05 #5
Robert wrote:
I maybe need to resize both the array and the actual string
in runtime so can someone please give me an example of that?


Robert...

You might find the functions at:

http://www.iedu.com/mrd/c/tokenize.c and
http://www.iedu.com/mrd/c/tokfile.c

of some interest. These programs defer allocation of storage
until the exact size of the storage needed is known (for both
pointer and char arrays.)

--
Morris Dovey
West Des Moines, Iowa USA
C links at http://www.iedu.com/c

Nov 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Federico G. Babelis | last post by:
Hi All: I have this line of code, but the syntax check in VB.NET 2003 and also in VB.NET 2005 Beta 2 shows as unknown: Dim local4 As Byte Fixed(local4 = AddressOf dest(offset)) ...
3
by: SilverWolf | last post by:
I need some help with sorting and shuffling array of strings. I can't seem to get qsort working, and I don't even know how to start to shuffle the array. Here is what I have for now: #include...
4
by: Simon Schaap | last post by:
Hello, I have encountered a strange problem and I hope you can help me to understand it. What I want to do is to pass an array of chars to a function that will split it up (on every location where...
7
by: arkobose | last post by:
hey everyone! i have this little problem. consider the following declaration: char *array = {"wilson", "string of any size", "etc", "input"}; this is a common data structure used to store...
12
by: arkobose | last post by:
my earlier post titled: "How to input strings of any lengths into arrays of type: char *array ?" seems to have created a confusion. therefore i paraphrase my problem below. consider the...
24
by: Michael | last post by:
Hi, I am trying to pass a function an array of strings, but I am having trouble getting the indexing to index the strings rather than the individual characters of one of the strings. I have...
2
by: Potiuper | last post by:
Question: Is it possible to use a char pointer array ( char *<name> ) to read an array of strings from a file in C? Given: code is written in ANSI C; I know the exact nature of the strings to be...
14
by: Shhnwz.a | last post by:
Hi, I am in confusion regarding jargons. When it is technically correct to say.. String or Character Array.in c. just give me your perspectives in this issue. Thanx in Advance.
11
by: Bob Rock | last post by:
Hello, I have an array of strings and need to find the matching one with the fastest possible code. I decided to order the array and then write a binary search algo. What I came up with is the...
3
by: Morten71 | last post by:
I have a strange problem. I have a local string() var I populate this way: clmns() As String = {"InvoiceNo", "InvoiceDate"} When I call: Array.IndexOf(clmns,"InvoiceDate") I get 0 (zero) as...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.