Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today

Thread Tools Search this Thread Display Modes
Old 11-18-2007, 06:28 PM   #11
Daemon Poster
RewtGuy's Avatar
Join Date: Dec 2004
Posts: 595
Send a message via AIM to RewtGuy
Default Re: new here

because length starts counting from 1 so the first character is outside the string (since it's backwords)

s o m e t h i n g (random ascii character here)
0 1 2 3 4 5 6 7 8 9

counting from 9 to 1

� g n i h t e m o
9 8 7 6 5 4 3 2 1

note the missing 'S'

length() starts from 1

when you do line = ("something") with line.length() it returns 9 then when you loop with cout << line[9]; you're reading memory from something else which you haven't written, thus it explains the weird random character. the loop completes before the last character (which would be the 10th cycle) is shown .

to fix that you could do while (counter > -1) Which would let it read the first character 'S'

and to fix the random ascii character you could do

counter = line.length();
while (counter > 0) {
cout << line[counter];
if (counter == -1);
else counter--;}

notice the bold and italic, this line sets the range from 8 to 0. which you want.

hopefully that helps and sorry if it was too late

Windows: A thirty-two bit extension and GUI shell to a sixteen bit patch to an eight bit operating system originally coded for a four bit microprocessor and sold by a two-bit company that can't stand one bit of competition.
RewtGuy is offline   Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

All times are GMT -5. The time now is 10:35 AM.

Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0