The malloc is correct but the way you assign values to pi is not.
I assume you want to store zero terminated strings in the buffer allocated by malloc.
You have to define a maximum length for all strings you enter (e.g. 10 bytes/characters). In the
for loop you then write:
Code:
for(i = 0; i < 5; i++)
{
r = scanf("%s",&pi[i*10]);
if(r != 1)
break;
}
Now when you want to print all strings you would write
Code:
for( i=0; i<5; i++ )
{
printf( "%s", &pi[i*10] );
}
This should print out everything correctly as long as the strings you enter are not longer than 9 characters.