Strings and Recursion


/*
Write a program on Strings and Recursion
*/


#include<stdio.h>
#include<string.h>

void display(char *str);
void Recdisplay(char *str);
int length(char *str);

main()
{
char str[100];
printf("Enter a string : ");
gets(str);
display( str );
printf("\n");
Recdisplay(str);
printf("\n");
printf("%d\n",length(str));
}

/*display*/
void display(char *str )
{
if(*str == '\0')
return;
putchar(*str );
display(str+1);
}

/*Recdisplay*/
void Recdisplay(char *str )
{
if(*str == '\0')
return;
Recdisplay(str+1);
putchar(*str );
}

/*length*/
int length(char *str )
{
if(*str == '\0')
return 0;
return (1 + length(str+1));
}

Post a Comment

0 Comments