1. ascii string question

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??

2. 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.

3. 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;
}

4. Originally Posted by sergioms
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:

Code:
if (iASCIIcode >= 'A' || iASCIIcode <= 'Z')
return 1;

if (iASCIIcode >= 'a' || iASCIIcode <= 'z')
return 2;
Saves trying to remember what the ascii codes are for different letters.

--
Mats

5. And what's wrong with isalpha, while we're here?

6. Originally Posted by sergioms
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;
}
Yuk! Magic numbers.