iswprint( ) in C++

C++Server Side ProgrammingProgramming

We are given with the task to show the working of iswprint( ). The iswprint( ) function in C++ STL is used to check that whether the given wide character can be printed or not. It is a function present in cwctype header file in C++. Wide characters is a computer character datatype that generally has a size greater than the traditional 8-bit character.

Syntax

int iswprint(c);

Parameter

c – This is a parameter which specifies the wide character that has to be checked whether it is printable or not.

Return Value

This function returns a non-zero value if c can be printed. It will return zero if c cannot be printed.

Following characters given below are printable

  • Upper case letters − A - Z

  • Lowercase letters − a - z

  • Digits − 0 - 9

  • Punctuation character − ! ” @ # $ % ^ & * ( ) } | \ ] [ _ - + ’ ? / . , } : ; ~ `

  • Space − ……

  • intable or not.

Example

#include <cwchar.h>
#include<iostream.h>
#inlude<cwctype.h>
Using namespace std;
int main( ){
   wchar_t str[ ] = “ authorized<channel<partners”;
   wcout<<str;
   for( int i = 0; i < wcslen(str); i++){
   if ( !iswprint(str[i]))
      str[i] = ‘ @ ’;
   }
   wcout<<str;
   return 0;
}

Output

If we run above code it will generate the following output

authorized<channel<partners
authorised@channel@partners

Example

#include <cwchar.h>
#include<iostream.h>
#inlude<cwctype.h>
Using namespace std;
int main( ){
   wchar_t str[ ] = “ and I am<= Iron Man”;
   wcout<<str;
   for( int i = 0; i < wcslen(str); i++){
      if ( !iswprint(str[i]))
         str[i] = ‘ & ’;
   }
   wcout<<str;
   return 0;
}

Output

if we run above code it will generate the following output

and I am<= Iron Man
and I am &&Iron Man
raja
Updated on 14-Aug-2020 08:18:19

Advertisements