My question is about efficiency of the swap char pointer algorithm.
Why either of the commented lines causes my complier to throw error?
The same logic works for swapping b with temp, but the same logic causes error while repeating in the same function for the temp and a?
Thank you all.
#include <iostream>
void sawp ( char *a, char *b, int l)
{
char * prtA = a;
char * prtB = b;
char *temp = (char *)calloc(l, sizeof(char));
while(*(char*)b)
{
*(char*)temp= *(char*)b;
// *(char*)b = *(char*)a;
// *(char*)a = *(char*)temp;
std::cout<<*(char*)temp<<std::endl;
b++;
temp++;
a++;
}
}
int main()
{
char *a="Name";
char *b="Lastname";
sawp (a,b,sizeof(b));
return 0;
}