C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 03-15-2004, 06:54 AM   #1
Registered User
 
Join Date: Mar 2004
Posts: 41
Storing multiple string in array

How can i store two string into an array ? I know the following code doesnt work. How can i modify the code so that it is able to store both the string in array form.

Code:
arrayx[0] = "abc";
arrayx[1] = "def";
winsonlee is offline   Reply With Quote
Old 03-15-2004, 07:17 AM   #2
Code Goddess
 
Prelude's Avatar
 
Join Date: Sep 2001
Posts: 9,661
Assuming your array was declared as
Code:
char arrayx[2][string_size];
Or
Code:
char *arrayx[2];
Where each element is dynamically allocated the proper amount of space:
Code:
strcpy ( arrayx[0], "abc" );
strcpy ( arrayx[1], "def" );
Don't forget to include string.h.
__________________
My best code is written with the delete key.
Prelude is offline   Reply With Quote
Old 03-15-2004, 07:49 AM   #3
Confused
 
Magos's Avatar
 
Join Date: Sep 2001
Location: Sweden
Posts: 3,122
Or:
Code:
char* arrayx[] =
{
  "abc",
  "def",
  "ghijkl"
};
__________________
MagosX.com

Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
Magos is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
String issues The_professor C++ Programming 7 06-12-2007 09:11 AM
RicBot John_ C++ Programming 8 06-13-2006 06:52 PM
can't assign proper values to an array of string Duo C Programming 1 04-04-2005 06:30 AM
Help with an Array omalleys C Programming 1 07-01-2002 08:31 AM


All times are GMT -6. The time now is 02:05 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22