Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using ascii for manipulating words

Status
Not open for further replies.

Sudoku

Programmer
Jun 25, 2006
5
CA
I am attempting to scramble a word using a key word that defines the positional shift of each letter(the difference between it and ![041]). If it reaches an end of its letter choices ![041] and ~[176] then it is moved to the other end and continues moving. To make it even more random the direction of the moving switches each turn.

Code:
for(n=0;n<sCode.length();n++,t++){
    if(sMaster.length()==t){
        t=0;
    }
    if(n % 2==0){
         for(w=0;w<sMaster.at(t)-041;w++){
              if(sCode.at(n)==176){
                  sCode.at(n)='!';
              }
              sCode.at(n)=sCode.at(n)+1;	
         }
    }
    else{
        for(w=0;w<sMaster.at(t)-041;w++){
            if(sCode.at(n)==041){
                sCode.at(n)='~';
            }
            sCode.at(n)=sCode.at(n)-1;	
        }
    }
}

This is my attempt at it and it crashes. I recieve the message "Unhandled exception in Directory.exe (KERNEL32.DLL): 0xE06D7363: Microsoft C++ Exception.".
I rarely play with ascii while programming so I am not sure if this is correct at all or if its one small thing.
 
If you run it in Debug mode, can you see which line it crashes on?
 
oh its first crash is at:

Code:
for(w=0;w<sMaster.at(t)-041;w++)
 
Try changing this
Code:
    if(sMaster.length()==t){
to this
Code:
    if(sMaster.length()>=t){
It could still crash if sMaster.length() == 0
 
Put this whole block of code in a try catch block. string::at() will throw an out_of_range exception if you try to access an invalid index.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top