c program to swap two strings

c program to swap two strings

C program to swap strings.

C programming code

#include<stdio.h>
#include<string.h>
#include<malloc.h>
#include<conio.h>

main()
{
   char first[100], second[100], *temp;

   printf("Enter the first string ");
   gets(first);

   printf("Enter the second string ");
   gets(second);

   printf("\nBefore Swapping\n");
   printf("First string: %s\n",first);
   printf("Second string: %s\n\n",second);

   temp = (char*)malloc(100); 

   strcpy(temp,first);
   strcpy(first,second);
   strcpy(second,temp);

   printf("After Swapping\n");
   printf("First string: %s\n",first);
   printf("Second string: %s\n",second);

   getch();
   return 0;
}
Advertisements

About pinku12

HIMANSHU SRIVASTAVA VARANASI
This entry was posted in Uncategorized. Bookmark the permalink.

2 Responses to c program to swap two strings

  1. Pingback: C Program to Calculating Area of Circle using Pointer | LET'S CODE

  2. Pingback: LET'S CODE

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s