Swap strings

C program to swap / exchange two string :

code

 

#include<stdio.h>
#include<conio.h>
void main()
{
char str1[10],str2[10],temp[10];

clrscr();
printf(“Enter first string :”);
scanf(“%s”,str1);
scanf(“%s”,str2);
strcpy(temp,str1);
strcpy(str1,str2);
strcpy(str2,temp);
printf(“\n String after exchange :”);
printf(“\n First string :%s”,str1);
printf(“\n Second string :%s”,str2);

getch();
}

 


output

Enter first string :hello

Enter second string:world

String after exchange :

first string :world

second string :hello

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s