Strings and recursion

C Programming Language / Number Class in java

654

Program:

#include<stdio.h>
#include<string.h>
void display(char *str);
void Rdisplay(char *str);
int length(char *str);
main( )
{
	char str[100];
	printf("Enter a string : ");
	gets(str);
	
	display( str );

	printf("\n");
	
	Rdisplay(str);
	
	printf("\n");
	printf("%d\n",length(str));
}/*End of main()*/

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


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


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

Output:

Enter a string : atnyla
atnyla
alynta
6
Press any key to continue . . .

Explanation:

Strings and recursion

This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.