//Write a program in c language to accept a string and reverse it without using strrev function of string.
#include <stdio.h>
#include <conio.h>
int main()
{
int i, len = 0;
char text[100], continue1;
clrscr();
do
{
printf("\nWrite the text to get its reverse: ");
gets(text);
for (i = 0; text[i] != NULL; i++)
len = len + 1;
printf("\nLength of string is %d\n", len);
printf("Reverse of entered text is ");
//reverse part
while (len >= 0)
{
printf("%c", text[len]);
len--;
}
printf("\npress y for continue or press any other key to exit: ");
scanf(" %c", &continue1);
} while (continue1 == 'y');
printf("\nThanking You");
return 0;
getch();
}
it's creating problem only in case of y means when program get repeat 2nd time. If I enter any other character as input then it's print last part and program get finished. The following result is shown on console.
Write the text to get its reverse: abc
Length of string is 3
Reverse of entered text is cba
press y for continue or press any other key to exit: y
Write the text to get its reverse:
Length of string is -1
Reverse of entered text is
press y for continue or press any other key to exit: