C library function - iscntrl()

Advertisements


Description

The C library function void 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) and 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 nonzero value if c is a control character, else 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, this will produce the following result:

all tutorials 


Advertisements
Advertisements