Previous Page
Next Page

iswalpha

Ascertains whether a given wide character is a letter of the alphabet

#include <wctype.h>
int iswalpha ( wint_t wc  );

The iswalpha( ) function is the wide-character version of the isalpha( ) character classification function. It tests whether its character argument is a letter of the alphabet. If the character is alphabetic, iswalpha( ) returns a nonzero value (that is, TRue); if not, the function returns 0 (false).

Which characters are considered alphabetic depends on the current locale setting for the localization category LC_CTYPE, which you can query or change using the setlocale( ) function. In all locales, the iswalpha( ) classification is mutually exclusive with iswcntrl( ), iswdigit( ), iswpunct( ) and iswspace( ).

Accented characters, umlauts, and the like are considered alphabetic only in certain locales. Moreover, other locales may have wide characters that are alphabetic, but that are neither upper- nor lowercase, or both upper- and lowercase.

Example

wint_t wc;

if ( setlocale( LC_CTYPE, "" ) == NULL)
{
  fwprintf( stderr,
            L"Sorry, couldn't change to the system's native locale.\n");
  return 1;
}
wprintf( L"The current locale for the 'isw ...' functions is '%s'.\n",
         setlocale(LC_CTYPE, NULL));

wprintf( L"Here is a table of the 'isw ...' values for the characters "
         L"from 128 to 255 in this locale:\n\n");

for ( wc = 128; wc < 255; ++wc )    // Loop iteration for each table row.
{
  if ( (wc-128) % 24 == 0 )         // Repeat table header every 24 rows.
  {
    wprintf(L"Code char alnum alpha blank cntrl digit graph lower"
            L" print punct space upper xdigit\n");
    wprintf(L"---------------------------------------------------"
            L"-------------------------------\n");
  }
  wprintf( L"%4u %4lc %3c %5c %5c %5c %5c %5c %5c %5c %5c %5c %5c %5c\n",
           wc,                              // Print numeric character code.
           ( iswprint( wc )  ? wc  : ' ' ), // Print the glyph, or a space
                                            // if it's not printable.
           ( iswalnum( wc )  ? 'X' : '-' ), // In a column for each
           ( iswalpha( wc )  ? 'X' : '-' ), // category, print X for
           ( iswblank( wc )  ? 'X' : '-' ), // yes or - for no.
           ( iswcntrl( wc )  ? 'X' : '-' ),
           ( iswdigit( wc )  ? 'X' : '-' ),
           ( iswgraph( wc )  ? 'X' : '-' ),
           ( iswlower( wc )  ? 'X' : '-' ),
           ( iswprint( wc )  ? 'X' : '-' ),
           ( iswpunct( wc )  ? 'X' : '-' ),
           ( iswspace( wc )  ? 'X' : '-' ),
           ( iswupper( wc )  ? 'X' : '-' ),
           ( iswxdigit( wc ) ? 'X' : '-' ) );
}  // end of loop for each character value

The following selected lines from the table produced by this program illustrate members of various categories:

Code char alnum alpha blank cntrl digit graph lower print punct space upper xdigit
----------------------------------------------------------------------------------
 128        -     -     -     X     -     -     -     -     -     -     -     -
 162    ¢   -     -     -     -     -     X     -     X     X     -     -     -
 163    £   -     -     -     -     -     X     -     X     X     -     -     -
 169    ©   -     -     -     -     -     X     -     X     X     -     -     -
 170    ª   X     X     -     -     -     X     -     X     -     -     -     -
 171    «   -     -     -     -     -     X     -     X     X     -     -     -
 180    ´   -     -     -     -     -     X     -     X     X     -     -     -
 181    m   X     X     -     -     -     X     X     X     -     -     -     -
 182    ¶   -     -     -     -     -     X     -     X     X     -     -     -
 185    1   -     -     -     -     -     X     -     X     X     -     -     -
 186    º   X     X     -     -     -     X     -     X     -     -     -     -
 191    ¿   -     -     -     -     -     X     -     X     X     -     -     -
 192    À   X     X     -     -     -     X     -     X     -     -     X     -

See Also

The corresponding function for byte characters, isalpha( ); iswalnum( ), iswblank( ), iswcntrl( ), iswdigit( ), iswgraph( ), iswlower( ), iswprint( ), iswpunct( ), iswspace( ), iswupper( ), iswxdigit( ), setlocale( ); the extensible wide-character classification function, iswctype( )


Previous Page
Next Page