Users Online

· Guests Online: 98

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

C Program to Copy One String to Another using Recursion

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
*/
#include <stdio.h>

void copy(char [], char [], int);

int main()
{
char str1[20], str2[20];

printf("Enter string to copy: ");
scanf("%s", str1);
copy(str1, str2, 0);
printf("Copying success.\n");
printf("The first string is: %s\n", str1);
printf("The second string is: %s\n", str2);
return 0;
}

void copy(char str1[], char str2[], int index)
{
str2[index] = str1[index];
if (str1[index] == '\0')
return;
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

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 0.92 seconds
10,836,377 unique visits