Originally Posted by
Mentallic
But I don't know how many strings I'll need to put into messages. If I make it messages[n] then I'm set on having only up to n strings, but may need more.
But my assignment has a .h file that the c file has included, and it has playerMessage defined as
typedef char playerMessage[MESSAGE_SIZE];
so I need to incorporate that into the code somehow, don't I?
playerMessage[MESSAGE_SIZE] is each string, but I have to store all of the strings in messages[].
Sorry, I misread your post, apparently. Does this help?
Code:
int main( void )
{
const int
STRING_COUNT = 10,
STRING_LENGTH = 100;
int
index;
char**
strings = malloc( STRING_COUNT * sizeof( char* ) );
for( index = 0; index < STRING_COUNT; ++index )
strings[ index ] = malloc( STRING_LENGTH * sizeof(char) );
/* do something useful here */
for( index = 0; index < STRING_COUNT; ++index )
free( strings[ index ] );
free( strings );
return 0;
}