The following code works for half the time when getting user input. However, sometimes if the user presses enter without entering anything, the program crashes. Sometimes, after typing a short command, and then a longer one the next time, the program again crashes. Other times the program crashes without pattern.
I have no idea what is causing this undefined behavior.
1 2 3 4 5 6 7 8 9
do{
cout << endl << "What do I do next?" << endl;
getline(cin,in2,'\n');
//Convert all letters to lowercase for ease on the processor.
for(int indx=0; indx<101; indx++){
if(isupper(in2[indx])) in2[indx]=tolower(in2[indx]);}
ProcCheckList(in2);
}while(play);
in2 = "";
I implemented that, and I really thought that was the solution since I never noticed that...
But the problem still persists...
New code:
1 2 3 4 5 6 7 8 9 10
do{
cout << endl << "What do I do next?" << endl;
getline(cin,in2,'\n');
//Convert all letters to lowercase for ease on the processor.
for(int indx=0; indx<in2.length(); indx++){
if(isupper(in2[indx])) in2[indx]=tolower(in2[indx]);}
ProcCheckList(in2);
in2 = "";
}while(play);
#include <iostream>
#include <string>
#include <stdlib.h>
#include <conio.h>
#include <cctype>
//#include "redirect_V2.h"
usingnamespace std;
int main(int argc, char *argv[]){
bool play=true;
string in2;
// Clean();
cout << "Ugh... I feel so groggy. Where am I? I think I need some 'help' here..." << endl;
do{
cout << endl << "What do I do next?" << endl;
getline(cin,in2,'\n');
//Convert all letters to lowercase for ease on the processor.
for(int indx=0; indx<in2.length(); indx++){
if(isupper(in2[indx])) in2[indx]=tolower(in2[indx]);}
// ProcCheckList(in2);
}while(play);
// Clean();
getch();
return 0;
}
Oh, and please disregard my use of conio.h. This is an incomplete, old program I'm trying to fix up. I want to focus on this current problem first.
//Convert all letters to lowercase for ease on the processor.
for(int indx=0; indx<in2.length(); indx++){
if(isupper(in2[indx])) in2[indx]=tolower(in2[indx]);}transform(in2.begin(), in2.end(), in2.begin(), ::tolower);
//ProcCheckList(in2);
I don't know of any problems other than not being able to use a custom locale. If you scroll down that stackoverflow page there is a similar example that uses locales.