Exetools  

Go Back   Exetools > General > General Discussion

Notices

Reply
 
Thread Tools Display Modes
  #1  
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
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



All times are GMT +8. The time now is 23:12.


Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX, chessgod101
( Since 1998 )