You have to use a char**, a pointer to pointer to char, to by able to capture a dynamic array of strings.
If you want 10 strings, you have to use:
char** strings = (char**)malloc(sizeof(char*)*10);
To store a string in the first element of the array, you have to use:
strings[0] = malloc(strlen("abcd")+1);
strpcy(strings[0], "abcd");
Here's a program that demonstrates the whole thing:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
char string[200];
char** strings = NULL;
int numStrings = 0;
int n = 0;
int i = 0;
/* Read the number of strings */
do
{
printf("Enter the number of strings (0 or higher): ");
n = scanf("%d", &numStrings);
} while ( n != 1 || numStrings < 0 );
/* Eat up the remaining characters afte the integer */
fgets(string, 199, stdin);
if ( numStrings > 0 )
{
/* Read the strings */
strings = (char**)malloc(numStrings*sizeof(char*));
for ( i = 0; i != numStrings; ++i )
{
printf("Enter a string: ");
fgets(string, 199, stdin);
strings[i] = malloc(strlen(string)+1);
strcpy(strings[i], string);
}
/* Print the strings back */
for ( i = 0; i != numStrings; ++i )
{
printf("%s", strings[i]);
}
/* Now release the memory back to the system */
/* First the individual strings */
for ( i = 0; i != numStrings; ++i )
{
free(strings[i]);
}
/* Now the array */
free(strings);
}
return 0;
}