C library function - iscntrl()



Description

The C library function int iscntrl(int c) checks if the passed character is a control character.

According to standard ASCII character set, control characters are between ASCII codes 0x00 (NUL), 0x1f (US), and 0x7f (DEL). Specific compiler implementations for certain platforms may define additional control characters in the extended character set (above 0x7f).

Declaration

Following is the declaration for iscntrl() function.

int iscntrl(int c);

Parameters

  • c − This is the character to be checked.

Return Value

This function returns non-zero value if c is a control character, else it returns 0.

Example

The following example shows the usage of iscntrl() function.

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

int main () {
   int i = 0, j = 0;
   char str1[] = "all \a about \t programming";
   char str2[] = "tutorials \n point";
  
   /* Prints string till control character \a */
   while( !iscntrl(str1[i]) ) {
      putchar(str1[i]);
      i++;
   }
  
   /* Prints string till control character \n */
   while( !iscntrl(str2[j]) ) {
      putchar(str2[j]);
      j++;
   }
   
   return(0);
}

Let us compile and run the above program, to produce the following result −

all tutorials 
ctype_h.htm
Advertisements