Header Ads Widget

Responsive Advertisement

Ticker

6/recent/ticker-posts

Write a c program for swapping of two string ?

 Write a c program for swapping 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;  
 } 
 

Post a Comment

1 Comments