-->
Showing posts with label program to swap two strings. Show all posts
Showing posts with label program to swap two strings. Show all posts

program to swap two strings

in turboc++
--------------------------------------------------------------------------------------------------
//program to swap two strings
#include <stdio.h>
#include<string.h>
#include<conio.h>
int main()
{
    char string[100],string1[100],tempo[100];
    printf("enter first string\n");
    gets(string);//accepts string
    printf("enter second string\n");
    gets(string1);
    printf("before swapping,strings are=%s and %s\n",string,string1);
    strcpy(tempo,string);//copies string to another
    strcpy(string,string1);//copies to string
    strcpy(string1,tempo);//copies string to string1

    printf("after swapping,strings are=%s and %s\n",string,string1);
     getch();
    return 0;
}
----------------------------------------------------------------------------------
in codeblocks
----------------------------------------------------------------------------------------------------
//program to swap two strings
#include <stdio.h>
#include<string.h>
int main()
{
    char string[100],string1[100],tempo[100];
    printf("enter first string\n");
    gets(string);//accepts string
    printf("enter second string\n");
    gets(string1);
    printf("before swapping,strings are=%s and %s\n",string,string1);
    strcpy(tempo,string);//copies string to another
    strcpy(string,string1);//copies to string
    strcpy(string1,tempo);//copies string to string1

    printf("after swapping,strings are=%s and %s\n",string,string1);

    return 0;
}