iswcntrl() function in C++ STL


The iswcntrl () function in C++ standard template library(STL) is used to check if the given wide character is a control character or not. A control character is a character in C/C++ that won’t occupy a printing position on a display screen. Iswcntrl() function is defined in a cwctype header file.

Syntax of iswcntrl() function is as follows

int iswcntrl (wint_t c)

Parameters − c − This is the character to be checked.

Return Value − A value different from zero (i.e.. a non-zero value) if c is a control character else a zero value.

Approach used in the below program is as follows

  • Input the string or character from the user
  • Traverse the loop till the control character is not found
  • Display the string till the first control character is not found
  • Exit from the loop when the first control character is examined

Example-1

 Live Demo

#include <stdio.h>
#include <wctype.h>
int main (){
   int i=0;
   wchar_t str[] = L"first line \n second line \n";
   while (!iswcntrl(str[i])) {
      putchar (str[i]);
      i++;
   }
   return 0;
}

Output

If we run the above code it will generate the following output −

First line

Example-2

 Live Demo

#include <stdio.h>
#include <wctype.h>
int main (){
   int i=0;
   wchar_t str[] = L"first linesecond line \nthird line";
   while (!iswcntrl(str[i])) {
      putchar (str[i]);
      i++;
   }
   return 0;
}

Output

If we run the above code it will generate the following output −

First linesecond line

Updated on: 30-Jan-2020

68 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements