title: swapping string in c using pointer
body: <p>Need help</p>
  
  <p>this is my code</p>
  
  <pre><code>void swapstringfun()
  {
     int i=0,j=0;
     char *str=(char *)malloc(sizeof(char)*15);
     char *mystr=(char *)malloc(sizeof(char)*15);
     system("cls");
     printf("Please enter first string :\t");
     scanf("%s",str);
     printf("Please enter second string :\t");
     scanf("%s",mystr);
     while(*(str+i)!='\0' &amp;&amp; *(mystr+i)!='\0')
     {
       *(str+i) ^=*(mystr+i);
       *(mystr+i) ^=*(str+i);
       *(str+i) ^=*(mystr+i);
       i++;
     }
     printf("%s swapped to %s",str,mystr);
     getch();
     main();
  }
  </code></pre>
  
  <p>I wrote the above code to swap the string using XOR operator. The problem with this code is. when my input is lets say.. <strong>RAJESH</strong> and <strong>ASHISH</strong>. Then, it shows output <strong>ASHISH</strong> and <strong>RAJESH</strong>. And, that is expected. </p>
  
  <p>But, when input is let say.. <strong>ABHISHEK</strong> and <strong>CODER</strong> .Then, output is <strong>CODERHEK</strong> and <strong>ABHIS</strong>. But, the expected output is <strong>CODER</strong> and <strong>ABHISHEK</strong>. Anyone help me to solve this problem. I will appreciate.</p>