NO

Author Topic: iscntrl(0) returns 0  (Read 3726 times)

Offline Robert

  • Member
  • *
  • Posts: 247
iscntrl(0) returns 0
« on: August 27, 2007, 07:58:32 PM »
Hi Pelle:

iscntrl(0) returns zero instead of a non-zero value.

#include <ctype.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
  {register int i;
for(i=0; i<=31; i+=1)
  {
    printf("% d\n",(int)iscntrl(i));
  }
  }
printf("% d\n",(int)iscntrl(127));
  return 0;   //  End of main program
}

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
Re: iscntrl(0) returns 0
« Reply #1 on: October 28, 2007, 10:43:56 PM »
This is by design, and I think it's correct -- but I will check again...
/Pelle

Offline Robert

  • Member
  • *
  • Posts: 247
Re: iscntrl(0) returns 0
« Reply #2 on: October 30, 2007, 05:02:22 AM »
Hi Pelle:

This issue came to my attention when I compiled the character tables (dftables.c) for PCRE. When dftables.c was compiled with the Pelle's C compiler output of a zero value was returned for the control character zero rather than the expected non-zero value. Here is some of what I have found regarding iscntrl().

"iscntrl returns a nonzero value if c is a control character (0x00 – 0x1F or 0x7F)."

quoted from

http://msdn2.microsoft.com/en-us/library/1ad6a790(VS.80).aspx

"iscntrl Returns nonzero for any character for which the isprint subroutine returns a value of False (0) and any character that is designated a control character in the current locale. For the C locale, control characters are the ASCII delete character (0177 or 0x7F), or an ordinary control character (less than 040 or 0x20). The iscntrl subroutine tests whether the character is of the cntrl class."

quoted from

http://publib.boulder.ibm.com/infocenter/systems/index.jsp?topic=/com.ibm.aix.basetechref/doc/basetrf1/ctype.htm

The "0177", which should read "0127", is a typo on the I.B.M. page.

Robert Wishlaw
« Last Edit: October 30, 2007, 05:11:14 AM by Robert »

Phil

  • Guest
Re: iscntrl(0) returns 0
« Reply #3 on: November 01, 2007, 11:56:32 AM »
On Linux systems with the GNU compiler, and also on Windows with the GNU MinGW compiler, iscntrl(0) returns a non-zero value.

The Linux man says:
Function: int iscntrl (int c)
Returns true if c is a control character (that is, a character that is not a printing character).


The '\0' character isn't a printing character, so iscntrl(0) must return a non-zero value.

Regards.

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: iscntrl(0) returns 0
« Reply #4 on: November 01, 2007, 03:56:38 PM »
First aid:
__ctypetab is in _crt.lib at offset 5243Ah
if you so change bytes 00 20 to 10 00 corrects that problem.
May the source be with you

Offline Robert

  • Member
  • *
  • Posts: 247
Re: iscntrl(0) returns 0
« Reply #5 on: November 03, 2007, 03:33:26 AM »
First aid:
__ctypetab is in _crt.lib at offset 5243Ah
if you so change bytes 00 20 to 10 00 corrects that problem.


I thank you timovjl, your First Aid is a good fix. Now when I run the code in the original post I get a value of 16, like all the other control characters, instead of 0.

Robert Wishlaw