I have recently started learning C++ and have written a few lines which accepts a string, displays the number of characters in it and also displays the reverse of the input string. This is what I have written.
#include <iostream>
int main()
{
char string[25],rev_string[25];
int counter=0,length=0;
std::cout << "\n Enter the string : ";
std::cin >> string;
while(counter==!'\0')
{
counter=counter+1;
length=length+1;
}
counter=0;
std::cout << "The string has "<<length<<" characters in it.";
while(length>=0)
{
rev_string[counter]=string[length];
counter=counter+1;
length=length-1;
}
std::cout << "\n The reverse of the given string is : "<<rev_string;
return(0);
}
There is no error when I debug, however when I run the program, I get some unexpected value and the string length shows zero. Can you please point out where have I made mistakes.
This is what I get when I run the program.