I have a quick question about using XOR two swap two string literals.
so I have the following:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void intSwap(int *a, int *b){
*a=*a^*b;
*b=*a^*b;
*a=*a^*b;
}
void swapString(char **a, char **b){
char *temp=*a;
*a=*b;
*b=temp;
}
void main(){
char *s= "ha";
char *t= "Oh";
printf("%s and %s \n",s,t); // prints ha Oh
swapString(&s,&t);
printf("%s and %s \n",s,t); // prints Oh ha
int a=10;
int b=5;
printf("%d %d\n",a,b); //print 10 5
intSwap(&a,&b);
printf("%d %d\n",a,b); //print 5 10
}
As you can see, I used binary operation XOR to for the intSwap. However, when I tried to do the same thing with swapString, it's not working.
I get error message saying: invalid operands to binary ^ (have ‘char *’ and ‘char *’)
Do you know how to use XOR to swap two string literals? Is it possible in C? Thanks ahead!!