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??
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
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
And what's wrong with isalpha, while we're here?
"I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008
"the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010
Why all the fuss?
Code:int CheckIsAlpha (char pchar) { return isalpha(pchar) ? ( islower(pchar) ? 2 : 1 ) : 0 ; }
Mainframe assembler programmer by trade. C coder when I can.