View Single Post
  #3  
Old 08-24-2006, 22:37
ArC ArC is offline
VIP
 
Join Date: Jan 2003
Location: NTOSKRNL.EXE
Posts: 172
Rept. Given: 0
Rept. Rcvd 1 Time in 1 Post
Thanks Given: 5
Thanks Rcvd at 17 Times in 12 Posts
ArC Reputation: 1
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.
Reply With Quote