/* Swapping two strings. */
#include <stdio.h>
int main()
{
char a[20], b[20], c[20];
int i;
printf("Enter string A: ");
gets(a);
printf("Enter string B: ");
gets(b);
printf("Before Swapping:\nString A = ");
puts(a);
printf("String B = ");
puts(b);
for(i = 0; b[i] != '\0'; i++)
c[i] = b[i];
c[i] = '\0';
for(i = 0; a[i] != '\0'; i++)
b[i] = a[i];
b[i] = '\0';
for(i = 0; c[i] != '\0'; i++)
a[i] = c[i];
a[i] = '\0';
printf("After Swapping:\nString A = ");
puts(a);
printf("String B = ");
puts(b);
return 0;
}
Comments
Post a Comment