This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

SWAP pointers

Function does work,like I hoped ...



char *swapdata (char *destination, char *SourceLine)
{
char *temp;
temp=SourceLine;
SourceLine=destination;
destination=temp;
printf("in function string = %s - %s\n",destination,SourceLine);
return temp;
}


void main(void)
{
char *p_test1,*p_test2;
char test1[] ="test 1";
char test2[] ="test 2";
result[128];


p_test1 = test1;
p_test2 = test2;
printf("string = %s - %s - %s\n",p_test1,p_test2,result);
result=swapdata(p_test1,p_test2);
printf("string = %s - %s - %s\n",p_test1,p_test2,result);
}

Function does not swap ???

Best regards

Parents
  • This works on my C52:

    #include <stdio.h>
    #include <reg52.h>
    
    char *swapdata (char **destination, char **SourceLine)
    {
      char *temp;
      temp=*SourceLine;
      *SourceLine=*destination;
      *destination=temp;
      printf("in function string = %s - %s\n",*destination,*SourceLine);
      return temp;
    }
    
    void main(void){
      char *p_test1,*p_test2;
      char test1[] ="test 1";
      char test2[] ="test 2";
      char *result;
    
      TI = 1;
    
      p_test1 = test1;
      p_test2 = test2;
      printf("string = %s - %s - %s\n",p_test1,p_test2,result);
      result=swapdata(&p_test1,&p_test2);
      printf("string = %s - %s - %s\n",p_test1,p_test2,result);
    
      while(1) ;
    }
    

Reply
  • This works on my C52:

    #include <stdio.h>
    #include <reg52.h>
    
    char *swapdata (char **destination, char **SourceLine)
    {
      char *temp;
      temp=*SourceLine;
      *SourceLine=*destination;
      *destination=temp;
      printf("in function string = %s - %s\n",*destination,*SourceLine);
      return temp;
    }
    
    void main(void){
      char *p_test1,*p_test2;
      char test1[] ="test 1";
      char test2[] ="test 2";
      char *result;
    
      TI = 1;
    
      p_test1 = test1;
      p_test2 = test2;
      printf("string = %s - %s - %s\n",p_test1,p_test2,result);
      result=swapdata(&p_test1,&p_test2);
      printf("string = %s - %s - %s\n",p_test1,p_test2,result);
    
      while(1) ;
    }
    

Children