strings

Z

Zach

Greetings,

I am writing a routine that will print out the beginning and end
strings for a game:

String A1 -> "Begin msg1"
String B1 -> "End msg1"

String A2 -> "Begin msg2"
String B2 -> "End msg2"

At the game start it prints a string and when game ends it prints a
matching string that is related to the first string such as
"Shakespeare awakens." (String A1) and then "Shakespear goes to
sleep." (String B1)

So the strings have to match.

First I thought of making one char pointer array and having 2
functions, one to print even numbered strings and another to print odd
numbered strings.

Then I thought maybe it would be better to make a 2 dimensional char
pointer array and have the first index print the beginning strings and
the second index print the end strings but I'm having trouble
implementing this.

Any ideas of simple code examples to illustrate putting strings into a
2d char array of pointers and printing out the strings would be
appreciated.

Zach
 
J

Joe Estock

Zach said:
Greetings,

I am writing a routine that will print out the beginning and end
strings for a game:

String A1 -> "Begin msg1"
String B1 -> "End msg1"

String A2 -> "Begin msg2"
String B2 -> "End msg2"

At the game start it prints a string and when game ends it prints a
matching string that is related to the first string such as
"Shakespeare awakens." (String A1) and then "Shakespear goes to
sleep." (String B1)

So the strings have to match.

First I thought of making one char pointer array and having 2
functions, one to print even numbered strings and another to print odd
numbered strings.

Then I thought maybe it would be better to make a 2 dimensional char
pointer array and have the first index print the beginning strings and
the second index print the end strings but I'm having trouble
implementing this.

Any ideas of simple code examples to illustrate putting strings into a
2d char array of pointers and printing out the strings would be
appreciated.

Zach

Why not create a struct for this?

struct message_t
{
char *message1;
char *message2;
};

struct message_t messages[10];

/* initialize with your data */
/* remainder of code here */
 

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
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top