print a string using recursion in c

Solutions on MaxInterview for print a string using recursion in c by the best coders in the world

showing results for - "print a string using recursion in c"
Simon
26 Oct 2017
1#include <stdio.h>
2
3/**
4* rec - a function that prints a string
5* Desc: use recursion to print a string one letter at a time
6*/
7void rec(char *s)
8{
9        if (*s == '\0')
10                return;
11        printf("%c", *s);
12        rec(s + 1);
13}
14
15/**
16* main - start of this program
17* Desc: implements on rec()
18* Return 0 on success
19*/
20int main()
21{
22        char str[100] = "My test string";
23        rec(str);
24        return 0;
25}