Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,938 questions

51,875 answers

573 users

How to copy one string to another using recursion in C

1 Answer

0 votes
#include <stdio.h>

void copy_recursion(char s1[], char s2[], int index) {
    s2[index] = s1[index];

    if (s1[index] == '\0')
        return;

    copy_recursion(s1, s2, index + 1);
}

int main(void) {
     char s1[16] = "c programming", s2[16];
 
    copy_recursion(s1, s2, 0);

    printf("s1: %s\n", s1);
    printf("s2: %s\n", s2);

    return 0;
}




/*
run:

s1: c programming
s2: c programming

*/

 



answered Jan 16, 2021 by avibootz

Related questions

1 answer 141 views
3 answers 299 views
1 answer 145 views
145 views asked Apr 28, 2018 by avibootz
2 answers 223 views
223 views asked Apr 28, 2018 by avibootz
1 answer 132 views
...