A
anonymous
Hi CLCers,
I tried the following code for swapping a string, but it is
not working. Inside the swap function the strings are
printed correctly, but when back in main() the strings are
not swapped at all. Thanks in advance. Here is the code.
#include<stdio.h>
int main()
{
void swap(char * string1, char * string2);
char * string1 = "Hello World";
char * string2 = "Hello Jupiter";
swap(string1, string2);
printf("%s\n%s\n",string1,string2);
return 0;
}
void swap( char * string1, char * string2)
{
char * temp;
temp = string1;
string1 = string2;
string2 = temp;
printf("%s\n%s\n",string1,string2);
}
Sha
I tried the following code for swapping a string, but it is
not working. Inside the swap function the strings are
printed correctly, but when back in main() the strings are
not swapped at all. Thanks in advance. Here is the code.
#include<stdio.h>
int main()
{
void swap(char * string1, char * string2);
char * string1 = "Hello World";
char * string2 = "Hello Jupiter";
swap(string1, string2);
printf("%s\n%s\n",string1,string2);
return 0;
}
void swap( char * string1, char * string2)
{
char * temp;
temp = string1;
string1 = string2;
string2 = temp;
printf("%s\n%s\n",string1,string2);
}
Sha