c++ - Checking what type each character in a string is -
i have function i'm using try check whether string in correct format. i'm trying looking @ each character , determining if of correct type. no matter try error cannot figure out. code below:
bool valid(string checkcode) { if(checkcode.length()!=6) return false; else if(isalpha(checkcode.at(0)))&(isalpha(checkcode.at(1)))&(isdigit(checkcode.at(2)))&(isdigit(checkcode.at(3)))&(isalpha(checkcode.at(4)))&(isalpha(checkcode.at(5))) return true; else return false; } the error i'm getting @ first '&' , says "error: expression must ivalue or function designator" i'm stuck here, appreciated.
isalpha(checkcode.at(0)))&(isalpha(checkcode.at(1))) //bit , should be
isalpha(checkcode.at(0)))&&(isalpha(checkcode.at(1))) //^^logical , you need use logical and in case.
you need make sure parentheses match.
//better format multiple conditions , make sure () match if( (isalpha(checkcode.at(0))) &&(isalpha(checkcode.at(1))) &&(isdigit(checkcode.at(2))) &&(isdigit(checkcode.at(3))) &&(isalpha(checkcode.at(4))) &&(isalpha(checkcode.at(5))) ) return true;
Comments
Post a Comment