C program to Swap two strings - My CS Tutorial - My CS Tutorial

Breaking

Programming languages full tutorial and programs, exam papers, visual basic( Vb.net ), information of new technologies and more....

Tuesday, January 28, 2020

C program to Swap two strings - My CS Tutorial

C program to swap to strings using  string library function.
We will swap two strings.
In this post we will discuss how to write a c program source code to swap two strings using string library function.
In the first user enter two strings then the compiler show the result before swapping and after swapping.


C program code


#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
 char st1[20],st2[20],st3[20];
 clrscr();
 printf("\n ENTER FIRST STRING:\n ");
 gets(st1);
 printf("\n ENTER SECOND STRING:\n ");
 gets(st2);
 printf("\n BEFORE SWAPPING STRINGS ARE:\n ");
 printf("\n FIRST STRING : %s\n ",st1);
 printf("\n SECOND STRING : %s\n",st2);
 strcpy(st3,st1);
 strcpy(st1,st2);
 strcpy(st2,st3);
 printf("\n AFTER SWAPPING STRINGS ARE:\n ");
 printf("\n FITST STRING : %s\n",st1);
 printf("\n SECOND STRING : %s\n",st2);

getch();
}


OUTPUT:




Please share this post and blog link with your friends.For more programs use this blog.
If you have any problem, please comment in comment box, subscribe this blog for notifications of new post on your email and follow this blog.If you have any method of this program or want to give any suggestion send email on hc78326@gmail.com

Created by-- HARSH CHAUHAN

No comments:

Post a Comment