![]() |
|
#3
|
|||
|
|||
|
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;
}
Code:
for( i=0; i<5; i++ )
{
printf( "%s", &pi[i*10] );
}
|
|
|