Follow Us

LightBlog

Breaking

Wednesday, March 1, 2017

Write a c program for swapping of two string ?



Write a c program for swapping of two string ?

#include <stdio.h>
#include <string.h>
#include <malloc.h>
int main()
{
   char f[100], str[100], *tmp;

   printf("Enter the first string\n");
   gets(f);

   printf("Enter the second string\n");
   gets(str);

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

   tmp = (char*)malloc(100);

   strcpy(tmp,f);
   strcpy(f,str);
   strcpy(str,t);

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

   return 0;
}


No comments:

Post a Comment