Swapping two strings

Swapping of two strings

Swapping two strings

In this program, we will see how to swap two strings in C Language . So, let’s move without any delay and learn how to swap two strings.

#include <stdio.h>
#include<conio.h>
void main() {
   char string1[] = "Techish Tech";     
   char string2[] = "EduNews.Tech";     
   char ch;

   int index = 0;

   //Character by Character approach

   printf("String before swapping - \n");
   printf("Value of string1 - %s \n", string1);
   printf("Value of string2 - %s \n", string2);

   while(string1[index] != '\0') {
      ch = string1[index];
      string1[index] = string2[index];
      string2[index] = ch;
      index++;
   }

   printf("String after swapping - \n");
   printf("Value of string1 - %s \n", string1);
   printf("Value of string2 - %s \n", string2);
printf("\n\n\n\t\t\tThankyou for Joining Us !");
    printf("\n\t\t\t!Regards EduNews !");

   getch();
}

Program Output:

swapping strings

I hope this post helps you to understand the “Swapping of two strings” and its implementation in C programming language.

Keep coding 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *