View Single Post
Old 10-23-2004, 07:32 PM   #7 (permalink)
Androto
Mac Os X User(I hate win)
 
Join Date: Oct 2004
Posts: 138
Androto is on a distinguished road
Quote:
Originally posted by Valmont
The question is: would the code below work?
Code:
sReversedWord[0]=sTheWord[0];
The anwer is NO. Why?
Because C++ did NOT allocate any space for sReversedWord. So sReversedWord[0] is not defined yet (does not exist), since this is the first element of that word. But there IS NO element at all yet.
We can solve this problem by allocating some space for sReversedWord:
Code:
//Watch the space in the initialization!
sReversedWord(" ");
AHA! Now there exists a sReversedWord[0]! So this works now:
Code:
sReversedWord[0]=sTheWord[0];
cout<<sReversedWord<<endl;
//OUTPUT: t
i don't understand what you mean by allocating space. are you saying that i have to make the compiler think that the sReversedWord string is an array before i can flip it around? i have no idea what is meant by this.

also, if i use this to flip around the word, would i still be able to use the rest of my own code?

one more thing. the error that i got before (parse error before ',' ) what exactly does that mean. my latest code is still the same as last time and still posted on the site.
Androto is offline   Reply With Quote