How would I store multiple strings that a user inputs? Also the user can enter as many strings as he wants until he enters an empty string ("str[0] == '\0').
I am guessing I would want to store each string into a different array but since the amount of strings is always changing how would I store them that can adapt to the amount of strings entered.
This is the code I have so far that simply loops everytime the user inputs a string.
Code:
int ch, count = 0;
char *result;
do
{
int i = 0;
str[0] = 0;
printf ("\nInput string values: ");
while ((ch = getchar()) != '\n' && i < 81)
{
str[i++] = ch;
str[i] = 0;
}
if (str[0] != '\0')
{
result = strtok(str, "\t ");
while (result != NULL)
{
printf ("\nstring %i %s \n", count, result);
count++;
result = strtok(NULL, "\t ");
}
}
}
while (str[0] != '\0');
Somewhere in that loop I need to store each of those strings and so I was wondering if there was a way to do that?