C Program for String Swapping

In this C program, We will see, how to do String swapping ” . So, let’s do it …

#include<stdio.h>
int main()
{
    char str1[15] = "C Program";
    char str2[15] = "python Program";
    char temp[15];

    printf("Before Swapping\n");
    printf("str1 = %s\n", str1);
    printf("str2 = %s\n\n", str2);

    strcpy(temp,str1);
    strcpy(str1,str2);
    strcpy(str2,temp);

    printf("After Swapping\n");
    printf("str1 = %s\n", str1);
    printf("str2 = %s\n", str2);

return 0;
}

Keep Learning with PrologiCode.

Leave a Comment