Hello ladies and gents,
I'm trying to reverse a string when one is entered with cin.getline, so when typing for example: testing
My output should become: gnitset
Ive written this piece of code and it works but, because the string has a certain length and not the whole length of the string is neccesarly being used the part wich is not used is also being shown in my output?
How do I get rid of this?
int main()
{
char tekst[20];
cout<< "Put in a line of text! ";
cin.getline(tekst, 20);
cout<< "Reverse the string now!" <<endl;
for (int i=0; i<sizeof tekst; i++)
cout<< tekst [sizeof tekst-i-1];
cout<<endl;
return 0;
}
Allready tried a search on this topic, came up with four possibilities and none really was sufficient for my problem, so thanks for the help in advance ;)