PDA

Click to See Complete Forum and Search --> : String Reverse...


CyberCarsten
Aug 4th, 2001, 11:38 PM
I'm trying to create a string reverser, but the program doesn't read out the result....can anyone tell me what I'm doing wrong...


#include <iostream.h>
#include <windows.h>

void main(){
char TempString[255];
char TheString[255];
int StringLen;

cout<<"Please enter string to reverse: ";
cin>>TempString;
StringLen = strlen(TempString);


for(int a = 0; a > 255; a++)
{

TheString[a] = TempString[StringLen - 1];
}



for(int index = 0; index > 255; index++)
{
cout<<TheString[a];
}
}

hmm
Aug 4th, 2001, 11:54 PM
CyberCarsten

The following line

// do while a is greater than 255, but a equals zero therefore wouldn’t do anything.

for(int a = 0; a > 255; a++)

should read

for(int a = 0; a < 255; a++)

HTH

hmm

P.S After some thought :o

#include <iostream.h>
#include <windows.h>

void main(){
char TempString[255];
char TheString[255];
int StringLen;
int a;
int pause;
cout<<"Please enter string to reverse: ";
cin>>TempString;
StringLen = strlen(TempString);


for(int a = 0; a < 255; a++)
{
TheString[a] = TempString[StringLen -a];
}


for(int index = 0; index < StringLen +1 ; index++)
{
cout<<TheString[index];
}
cin >>pause;
}

CyberCarsten
Aug 5th, 2001, 12:11 AM
Thanks! ;)

Now I got the result, but it's not letters...it's just alot of |[]

????

CyberCarsten
Aug 5th, 2001, 12:13 AM
It works!! Thank you very much! :)

hmm
Aug 5th, 2001, 12:16 AM
CyberCarsten

Have a look at the p.s of my first post ( I was modifying it has you were reading it ). I've changed some other parts



hmm :)

CyberCarsten
Aug 5th, 2001, 01:38 AM
It works perfect! Thanks! :)

hmm
Aug 5th, 2001, 02:00 AM
Its nice to answer one, rather than always asking them ;)

hmm:D

CyberCarsten
Aug 5th, 2001, 04:33 AM
Hehe! I feel the same way! :D