Displaying an input line backwards by recursion in C

#include <stdio.h>
 
 void display();
 
 int main()
 {
    printf("Input a line : ");
    display();
    printf("n");
    return 0;
 }
 
 void display()
 {
    char ch;
 
    if((ch = getchar()) != 'n')
        display();
    putchar(ch);
 }

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.