C program to swap two strings using user define function
Given two strings and we have to swap them using function in C programming language.
In this program, we are not using any library function like strcpy(), memcpy() etc, except strlen() - we can also create a function for it. But, the main aim is to swap the strings using function.
Read: C program to implement strlen() function in C
Example:
Input strings:
String1: "Hello"
String2: "World"
Output:
String1: "World"
String2: "Hello"
Here is the function that we are using in the program,
void swapstr(char *str1 , char *str2)
Here,
- void is the return type
- swapstr is the name of the string
- char *str1 is the character pointer that will store the address of given string1 while calling the function
- char *str2 is the another character pointer that will store the address of given string2 while calling the function
Function calling statement:
swapstr(string1, string2);
Program to swap two strings using user define function in C
Output
need an explanation for this answer? contact us directly to get an explanation for this answer