I debugged the program.
All working fine.
But when I return b in strdup(), it is not really returning to the main
program. That is, after the function call 'strdup' the value of b is not
'dinesh' bcos the address of b [assigned in strdup( )]  is changed while
returning.

Is this clear ?
Just do a cut and paste and test this code.
Thanks all.

Dinesh.



char * strdup(char *a)
{
 UInt16 len;
 char *b;

  len = StrLen(a);
  if ( (b = MemPtrNew( len + 1 )) == NULL )  /* Address X assigned to b*/
   return( NULL );
  StrCopy(b,a);
  return(b);
 }


 Boolean IvoxFormHandleEvent(EventPtr event)
 {
 ...
 ....
    switch (event->eType) {
    case ctlSelectEvent:  // A control button was pressed and released.
   if (event->data.ctlSelect.controlID == MainRecordButton)
   {
    char *a;
    char *b;
    a = MemPtrNew(10);
    StrCopy(a,"dinesh");
    b = strdup(a);
    /* Problem : Here is the Address of b is not X, so the value of b is not
"dinesh"*/
    MemPtrFree(a);
    MemPtrFree(b);
   }
 ...
 ...
 }










-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to