how to check that a strings chars are sorted in an ascending order regarding their ascii code
and consist only for this ranges a-z A-Z
??
how to extract the ascii code from each cell??
Printable View
how to check that a strings chars are sorted in an ascending order regarding their ascii code
and consist only for this ranges a-z A-Z
??
how to extract the ascii code from each cell??
loop through the string, return false if you get to something not in a-z A-Z, or an element smaller than the last. Return true if you reach the end.
Code://
// 1 = Upper Char (A-Z)
// 2 = Lower Char (a-z)
// 0 - Not Alpha Char.
//
int CheckIsAlpha (char pchar){
int iASCIIcode;
iASCIIcode = pchar;
if (iASCIIcode >= 65 || iASCIIcode <= 90)
return 1;
if (iASCIIcode >= 97 || iASCIIcode <= 122)
return 2;
return 0;
}
Surely this is at least easier to read, even if it doesn't really fix problems with EBCDIC and other non-ASCII characters sets:
Saves trying to remember what the ascii codes are for different letters.Code:if (iASCIIcode >= 'A' || iASCIIcode <= 'Z')
return 1;
if (iASCIIcode >= 'a' || iASCIIcode <= 'z')
return 2;
--
Mats
And what's wrong with isalpha, while we're here?
Why all the fuss?
Code:int CheckIsAlpha (char pchar) {
return isalpha(pchar) ? ( islower(pchar) ? 2 : 1 ) : 0 ;
}