Board index » cppbuilder » Questions re: return values from isalpha, isprint

Questions re: return values from isalpha, isprint


2004-09-09 01:43:36 AM
cppbuilder21
I have inherited some very old C code for a DLL. We are migrating it to
C++, using BCB6 Build 10.166. Running on WinXP Pro.
The following syntax occurs inside a heavily-used parsing function:
char t_source[] = "1234567890`~!@#$%^&*()-_=+" \
"AaBbCcDdEeFfGgHhIiJjKkLl" \
"MmNnOoPpQqRrSsTtUuVvWwXxYyZz" \
"{}[]\\|;:'\",<>./? ";
char result;
for (int i = 0; i < strlen(t_source); i++) {
result = (char)isalpha(t_source[i]);
if (!result) break;
}
When this code encounters any alphabetic character, it returns false.
(e.g., isalpha('A') == 256; (char)256 == '\0').
When I compile using {*word*76}shed Dev-C++ (rev. 4.9.9.0, no updates
applied), the return value of isalpha is 1 for uppercase A..Z, 2 for
lowercase a..z. Casting 1 or 2 to char yields a non-zero value, so the
code I inherited works as the original programmer intended.
I'm encountering a similar issue with isprint-- alpha characters g..z
and G..Z return value 256, which (still) casts to '\0'. (Alpha
characters a..f and A..F return value 384.)
Compiling with Dev-C++, isprint returns 1 for uppercase A..Z, and 2 for
lowercase a..z.
MY QUESTIONS:
1. Is implementation of return values at the discretion of the vendor?
2. If the answer to 1 is "Yes", was there a reason for the odd
discrepancy in isprint (384 for aA..fF, 256 for gG..zZ)?
3. Is there some portion of the BCB documents I should have read so that
I didn't have to bother you with this question?
Thanks for your help.
Kathleen
 
 

Re:Questions re: return values from isalpha, isprint

That is old-timy C++ code, not C code.
Change 'result' to type int.
. Ed
Quote
Kathleen Beaumont wrote in message
news: XXXX@XXXXX.COM ...
 

Re:Questions re: return values from isalpha, isprint

Ed Mulroy [TeamB] wrote:
Quote
That is old-timy C++ code, not C code.

Yes, the project is rife with that...
Quote
Change 'result' to type int.
Thanks,
Kathleen
Quote

. Ed


>Kathleen Beaumont wrote in message
>news: XXXX@XXXXX.COM ...




 

{smallsort}