C Tutorial/Wide Character String/Wide Character Functions

Материал из C\C++ эксперт
Перейти к: навигация, поиск

An open-ended means of classifying characters.

Header file wctype.h Declaration wctype_t wctype(const char *attr);int iswctype(wint_t ch, wctype_t attr_ob);

  1. alnum
  2. digit
  3. print
  4. upper
  5. alpha
  6. graph
  7. punct
  8. xdigit
  9. cntrl
  10. lower
  11. space

The following fragment demonstrates the wctype() and iswctype() functions:


<source lang="cpp">#include <wctype.h>

  1. include <stdio.h>

int main(void){

 wctype_t x;
 x = wctype("space");
 if(iswctype(L" ", x)){
   printf("Is a space.\n");
 }

}</source>

Multibyte/Wide-Character Conversion Functions

They use the header <wchar.h>.

Wide-Character/Multibyte Conversion Functions

Function Description win_t btowc(int ch) Converts ch into its wide-character equivalent and returns the result. Returns WEOF on error or if ch is not a one-byte, multibyte character. size_t mbrlen(const char *str, size_t num,mbstate_t *state) Restartable version of mblen() as described by state. Returns a positive value that indicates the length of the next multibyte character. Zero is returned if the next character is null. A negative value is returned if an error occurs. size_t mbrtowc(wchar_t *out,const char *in,size_t num,mbstate_t *state) Restartable version of mbtowc() as described by state. Returns a positive value that indicates the length of the next multibyte character. Zero is returned if the next character is null. A value of -1 is returned if an error occurs and the macro EILSEQ is assigned to errno. If the conversion is incomplete, -2 is returned. int mbsinit(const mbstate_t *state) Returns true if state represents an initial conversion state. size_t mbsrtowcs(wchar_t *out,const char **in,size_t num, mbstate_t state) Restartable version of mbstowcs() as described by state. Also, mbsrtowcs() differs from mbstowcs() in that in is an indirect pointer to the source array. If an error occurs, the macro EILSEQ is assigned to errno. size_t wcrtomb(char *out, wchar_t ch, mbstate_t *state) Restartable version of wctomb() as described by state. If an error occurs, the macro EILSEQ is assigned to errno. size_t wcsrtombs(char *out, const wchar_t **in, size_t num, mbstate_t *state) Restartable version of wcstombs() as described by state. Also, wcsrtombs() differs from wcstombs() in that in is an indirect pointer to the source array. If an error occurs, the macro EILSEQ is assigned to errno. int wctob(wint_t ch) Converts ch into its one-byte, multibyte equivalent. It returns EOF on failure.

(C: The Complete Reference, Fourth Edition by Herbert Schildt McGraw-Hill/Osborne 2000 ISBN-10: 0072121246, ISBN-13: 978-0072121247)

Wide-Character Array Functions

These functions use the header <wchar.h>.

Wide-Character Array Functions and Their char Equivalents

Function char Equivalent wchar_t *wmemchr(const wchar_t *str,wchar_t ch, size_t num) memchr() int wmemcmp(const wchar_t *str1,const wchar_t *str2, size_t num) memcmp() wchar_t *wmemcpy(wchar_t *str1, const wchar_t *str2, size_t num) memcpy() wchar_t *wmemmove(wchar_t *str1, const wchar_t *str2, size_t num) memmove() wchar_t *wmemset(wchar_t *str, wchar_t ch, size_t num) memset()

(C: The Complete Reference, Fourth Edition by Herbert Schildt McGraw-Hill/Osborne 2000 ISBN-10: 0072121246, ISBN-13: 978-0072121247)

Wide-Character Functions

  1. The wide-character functions use two headers: <wchar.h> and <wctype.h>.
  2. The header <wctype.h> defines the types wint_t, wctrans_t, and wctype_t.
  3. The wide-character functions operate on characters of type wchar_t, which are 16 bits.
  4. The types wctrans_t and wctype_t are used to represent a character mapping (character translation) and the classification of a character, respectively.
  5. The wide-character EOF is defined as WEOF.
  6. The mbstate_t type describes the state of conversion from a multibyte to wide-character .
  7. The <wchar.h> header also defines the macros NULL, WEOF, WCHAR_MAX, and WCHAR_MIN. The last two define the maximum and minimum value that can be held in an object of type wchar_t.

16.1.Wide Character Functions 16.1.1. Wide-Character Functions 16.1.2. <A href="/Tutorial/C/0300__Wide-Character-String/WideCharacterIOFunctions.htm">Wide-Character I/O Functions</a> 16.1.3. <A href="/Tutorial/C/0300__Wide-Character-String/WideCharacterStringFunctions.htm">Wide-Character String Functions</a> 16.1.4. <A href="/Tutorial/C/0300__Wide-Character-String/WideCharacterStringConversionFunctions.htm">Wide-Character String Conversion Functions</a> 16.1.5. <A href="/Tutorial/C/0300__Wide-Character-String/WideCharacterArrayFunctions.htm">Wide-Character Array Functions</a> 16.1.6. <A href="/Tutorial/C/0300__Wide-Character-String/MultibyteWideCharacterConversionFunctions.htm">Multibyte/Wide-Character Conversion Functions</a> 16.1.7. <A href="/Tutorial/C/0300__Wide-Character-String/Anopenendedmeansofclassifyingcharacters.htm">An open-ended means of classifying characters.</a>

Wide-Character I/O Functions

The wide-character I/O functions use the header <wchar.h>.

Wide-Character I/O Functions and Their char Equivalents

Function char Equivalent win_t fgetwc(FILE *stream) fgetc() wchar_t *fgetws(wchar_t *str, int num,FILE *stream) fgets() wint_t fputwc(wchar_t ch, FILE *stream) fputc() int fputws(const wchar_t *str, FILE *stream) fputs() int fwprintf(FILE *stream,const wchar_t *fmt, ...) fprintf() int fwscanf(FILE *stream,const wchar_t *fmt, ...) fscanf() wint_t getwc(FILE *stream) getc() wint_t getwchar(void) getchar() wint_t putwc(wchar_t ch, FILE *stream) putc() wint_t putwchar(wchar_t ch) putchar() int swprintf(wchar_t *str, size_t num,const wchar_t *fmt, ...) sprintf() int swscanf(const wchar_t *str,const wchar_t *fmt, ...) sscanf() wint_t ungetwc(wint_t ch, FILE *stream) ungetc() int vfwprintf(FILE *stream,const wchar_t *fmt, va_list arg) vfprintf(). int vfwscanf(FILE * restrict stream,const wchar_t * restrict fmt,va_list arg); vfscanf() int vswprintf(wchar_t *str, size_t num,const wchar_t *fmt, va_list arg) vsprintf() int vswscanf(const wchar_t * restrict str, const wchar_t * restrict fmt,va_list arg); Vsscanf() int vwprintf(const wchar_t *fmt, va_list arg) vprintf() int vwscanf(const wchar_t * restrict fmt, va_list arg); vscanf() int wprintf(const wchar_t *fmt, ...) printf() int wscanf(const wchar_t *fmt, ...) scanf()

(C: The Complete Reference, Fourth Edition by Herbert Schildt McGraw-Hill/Osborne 2000 ISBN-10: 0072121246, ISBN-13: 978-0072121247)

Wide-Character String Conversion Functions

These functions use the header <wchar.h>.

Wide-Character Conversion Functions and Their char Equivalents

Function char Equivalent size_t wcsftime(wchar_t *str, size_t max, const wchar_t *fmt, const struct tm *ptr) strftime() double wcstod(const wchar_t *start, wchar_t **end); strtod() float wcstof(const wchar_t * restrict start, wchar_t ** restrict end); strtof() long double wcstold(const wchar_t * restrict start, wchar_t ** restrict end); strtold() long int wcstol(const wchar_t *start, wchar_t **end,int radix) strtol() long long int wcstoll(const wchar_t * restrict start,wchar_t ** restrict end,int radix) strtoll() unsigned long int wcstoul(const wchar_t * restrict start, wchar_t ** restrict end,int radix) strtoul() unsigned long long int wcstoull( const wchar_t *start, wchar_t **end, int radix) Strtoull()

(C: The Complete Reference, Fourth Edition by Herbert Schildt McGraw-Hill/Osborne 2000 ISBN-10: 0072121246, ISBN-13: 978-0072121247)

Wide-Character String Functions

They use the header <wchar.h>.

Wide-Character String Functions and Their char Equivalents

Function char Equivalent wchar_t *wcscat(wchar_t *str1, const wchar_t *str2) strcat() wchar_t *wcschr(const wchar_t *str, wchar_t ch) strchr() int wcscmp(const wchar_t *str1,const wchar_t *str2) strcmp() int wcscoll(const wchar_t *str1, const wchar_t *str2) strcoll() size_t wcscspn(const wchar_t *str1, const wchar_t *str2) strcspn() wchar_t *wcscpy(wchar_t *str1, const wchar_t *str2) strcpy() size_t wcslen(const wchar_t *str) strlen() wchar_t *wcsncpy(wchar_t *str1, const wchar_t str2, size_t num) strncpy() wchar_t *wcsncat(wchar_t *str1, const wchar_t str2, size_t num) strncat() int wcsncmp(const wchar_t *str1, const wchar_t *str2,size_t num) strncmp() wchar_t *wcspbrk(const wchar_t *str1, const wchar_t *str2) strpbrk() wchar_t *wcsrchr(const wchar_t *str, wchar_t ch) strrchr() size_t wcsspn(const wchar_t *str1), const wchar_t *str2) strspn() wchar_t *wcstok(wchar_t *str1, const wchar_t *str2, wchar_t **endptr) strtok() wchar_t *wcsstr(const wchar_t *str1, const wchar_t *str2) strstr() size_t wcsxfrm(wchar_t *str1, const wchar_t *str2, size_t num) Strxfrm()

(C: The Complete Reference, Fourth Edition by Herbert Schildt McGraw-Hill/Osborne 2000 ISBN-10: 0072121246, ISBN-13: 978-0072121247)