C Program to Swap Two Strings Using strcpy()

in this C program Swapping two strings involves exchanging the content of two character arrays. Here’s a simple program that demonstrates how to swap two strings.

Program :

#include<stdio.h>
#include<string.h>
#include<malloc.h>
#include<conio.h>
main()
{
char input1[100],input2[100],*temp;
printf(“Enter the first string : “);
gets(input1);
printf(“Enter sceond string : “);
gets(input2);
printf(“\nBefore Swapping\n”);
printf(“First Strings : %s\n”,input1);
printf(“Second Strings : %s\n\n”,input2);

temp =(char*)malloc(100);
strcpy(temp,input1);
strcpy(input1,input2);
strcpy(input2,temp);
printf(“After Swapping\n”);
printf(“First String : %s”,input1);
printf(“\nSecond String: %s”,input2);
getch();
return 0;

}

Output :

Leave a Comment

Your email address will not be published. Required fields are marked *

6 thoughts on “C Program to Swap Two Strings Using strcpy()”

  1. Точно актуальные события мировых подиумов.
    Все новости известнейших подуимов.
    Модные дома, лейблы, гедонизм.
    Свежее место для стильныех людей.
    https://metamoda.ru/
    [url=https://metamoda.ru/]https://metamoda.ru/[/url]

  2. Несомненно трендовые новинки модного мира.
    Все новости самых влиятельных подуимов.
    Модные дома, торговые марки, гедонизм.
    Интересное место для модных хайпбистов.
    https://femalemoda.ru/

  3. Абсолютно трендовые новости мировых подиумов.
    Все новости мировых подуимов.
    Модные дома, торговые марки, haute couture.
    Интересное место для трендовых людей.
    https://breakmoda.ru/

Shopping Basket
Select the fields to be shown. Others will be hidden. Drag and drop to rearrange the order.
  • Image
  • SKU
  • Rating
  • Price
  • Stock
  • Availability
  • Add to cart
  • Description
  • Content
  • Weight
  • Dimensions
  • Additional information
Click outside to hide the comparison bar
Compare
Verified by MonsterInsights