Easy Tutorial
❮ C Function Strxfrm C Exercise Example47 ❯

C Library Function - iscntrl()

C Standard Library - <ctype.h>

Description

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

According to the standard ASCII character set, control characters are ASCII codes between 0x00 (NUL) and 0x1f (US), and 0x7f (DEL). Some platform-specific compiler implementations may also define additional control characters in the extended character set (above 0x7f).

Declaration

Here is the declaration for the iscntrl() function.

int iscntrl(int c);

Parameters

Return Value

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

Example

The following example demonstrates the use of the iscntrl() function.

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

int main ()
{
   int i = 0, j = 0;
   char str1[] = "all \a about \t programming";
   char str2[] = "tutorialpro \n tutorials";

   /* Output string until control character \a */
   while( !iscntrl(str1[i]) ) 
   {
      putchar(str1[i]);
      i++;
   }

   /* Output string until control character \n */
   while( !iscntrl(str2[j]) ) 
   {
      putchar(str2[j]);
      j++;
   }

   return(0);
}

Let's compile and run the above program, which will produce the following result:

all tutorialpro

C Standard Library - <ctype.h>

❮ C Function Strxfrm C Exercise Example47 ❯