C program to swap two strings, i.e., their contents are interchanged.
#include <stdio.h> #include <string.h> int main() { char first[100], second[100], t[100]; printf("Enter first string\n"); gets(first); printf("Enter second string\n"); gets(second); printf("\nBefore Swapping\n"); printf("First string: %s\n", first); printf("Second string: %s\n\n", second); strcpy(t, first); strcpy(first, second); strcpy(second, t); printf("After Swapping\n"); printf("First string: %s\n", first); printf("Second string: %s\n", second); return 0; }
output:
Before Swapping:
hello
First string:
bye
Second string: hello
After Swapping bye
First string: bye
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
output:
Before Swapping:
hello
First string:
bye
Second string: hello
After Swapping bye
First string: bye
Second string: hello
need an explanation for this answer? contact us directly to get an explanation for this answer