This C Program uses recursive function & copies a string entered by user from one character array to another character array.
Here is the source code of the C program to copy string using recursion. The C Program is successfully compiled and run on a Linux system. The program output is also shown below.
* C Program to Copy One String to Another using Recursion
void copy(char , char , int);
char str1, str2;
printf("Enter string to copy: ");
copy(str1, str2, 0);
printf("The first string is: %s\n", str1);
printf("The second string is: %s\n", str2);
void copy(char str1, char str2, int index)
str2[index] = str1[index];
if (str1[index] == '\0')
copy(str1, str2, index + 1);
$ cc pgm10.c $ a.out Enter string to copy: sanfoundry Copying success. The first string is: sanfoundry The second string is: sanfoundry
Sanfoundry Global Education & Learning Series – 1000 C Programs.
If you wish to look at other example programs on Strings, go to C Programming Examples on Strings. If you wish to look at programming examples on all topics, go to C Programming Examples.
« Prev Page - C Program to Convert Binary Code of a Number into its Equivalent Gray’s Code without using Recursion