Our website is made possible by displaying online advertisements to our visitors.Please consider supporting us by disabling your ad blocker.
Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu
Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Translate it in your own Language

Print this Job Post

Print Friendly and PDF

Friday, May 30, 2014

C program to swap two strings

C programming code

#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include<conio.h>
void main()
{
   char first[100], second[100], *temp;
   clrscr();
   printf("Enter the first string\n");
   gets(first);
   printf("Enter the second string\n");
   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();
}

Output of program:



No comments:

Post a Comment

Copyright @ CrackMNC 2014-2024
Divas Nikhra Theme by Crack MNC