I am trying to check whether an input string is alphanumeric or more uppercase or empty. If the input string is among the above-malfunctioned strings, I simply want to return false/0 otherwise work with rest of the program which is working fine. The chunk of my program which is given problem :
std::string myfunc(std::string input){
std::string b="";
if (!input.size()) return 0;
for (int i = 0; i < input.size(); i++){
if ( input[i] < 'a' || input[i] > 'z'|| isalpha(input[i]) || isupper(input[i]) ) return 0;
}
b = input;
//just copy the input string for now.
return b;
}
and I call this function as
int main(){
std::string input="Somthing";
std::cout << myfunc(input)<< std::endl;
return 0;
}
getting the below error?
terminate called after throwing an instance of 'std::logic_error'
what(): basic_string::_M_construct null not valid
Aborted (core dumped)
This program runs well without these two edge cases. I am not able to understand the error and find a fix to it? Any suggestions on what I am doing wrong?