I'm just starting to learn C, so if you can, please don't be so hard on me. I'm trying to learn how to allocate memory for arrays, so i started with someting like this. I just wanna dynamicly allocate memory for array of strings, and then display it.
int main( )
{
int number, i;
scanf ("%d", &number);
char **table =(char **) malloc(number*sizeof(char*));
for(i=0; i<number; i++)
{
table[i] = (char *)malloc(6);
}
for(i=0; i<number; i++)
{
scanf("%s", &table[i]);
}
for(i=0; i<number; i++)
{
printf("Person nr %d : %s ", i+1, &table[i]);
}
for(i=0; i<number; i++)
{
free(table[i]);
}
free(table);
return 0;
}
But program only works when i type words with 3 or less letters. So, I don't know if i have a problem with memory allocation, or maybe i i just can't print with %s for **char? Maybe someone could tell me where I'm doing wrong and explain why?
Thank you for taking the time to read it :)