# wctype

***

**1. Character Classification:**

```c
#include <wctype.h>

int main() {
  wint_t wc = L'A';
  if (iswalpha(wc)) {
    printf("'%lc' is an alphabetical character.\n", wc);
  }
  return 0;
}
```

**2. Case Conversion:**

```c
#include <wctype.h>

int main() {
  wint_t wc = L'a';
  wc = towupper(wc);
  printf("'%lc' converted to uppercase is '%lc'.\n", wc);
  return 0;
}
```

**3. Character Width Determination:**

```c
#include <wctype.h>

int main() {
  wint_t wc = L'あ';
  int width = wcswidth(&wc, 1);
  printf("The width of character '%lc' is %d.\n", wc, width);
  return 0;
}
```

**4. Text Collation:**

```c
#include <wctype.h>
#include <locale.h>

int main() {
  setlocale(LC_COLLATE, "en_US.UTF-8");
  wint_t a = L'A', b = L'B';
  int cmp = wcscoll(&a, &b);
  printf("The result of strcmp() is %d.\n", cmp);
  return 0;
}
```

**5. Character Transformation:**

```c
#include <wctype.h>

int main() {
  wint_t wc = L'é';
  wc = towlower(wc);
  printf("'%lc' transformed to lowercase is '%lc'.\n", wc);
  return 0;
}
```

**6. Character Mapping:**

```c
#include <wctype.h>
#include <wchar.h>

int main() {
  wchar_t wcs[] = L"Hello, world!";
  for (size_t i = 0; i < wcslen(wcs); i++) {
    wint_t wc = towupper(wcs[i]);
    wcs[i] = wc;
  }
  printf("Uppercase string: %ls\n", wcs);
  return 0;
}
```

**7. Case-Insensitive String Comparison:**

```c
#include <wctype.h>

int main() {
  const wchar_t *str1 = L"Hello", *str2 = L"HELLO";
  int cmp = wcscasecmp(str1, str2);
  printf("Result of wcscasecmp(): %d\n", cmp);
  return 0;
}
```

**8. Character Set Determination:**

```c
#include <wctype.h>

int main() {
  wint_t wc = L'€';
  if (iswspace(wc)) {
    printf("'%lc' is a whitespace character.\n", wc);
  }
  return 0;
}
```

**9. Wide String Manipulation:**

```c
#include <wctype.h>
#include <wchar.h>

int main() {
  wchar_t wcs[] = L"Hello, world!";
  size_t idx = wcscspn(wcs, L" !.");
  printf("The length of the initial segment without spaces: %zu\n", idx);
  return 0;
}
```

**10. String Tokenization:**

```c
#include <wctype.h>

int main() {
  const wchar_t *str = L"This is a sample string";
  wchar_t *token = wcstok(wstr, L" ");
  while (token != NULL) {
    printf("%ls\n", token);
    token = wcstok(NULL, L" ");
  }
  return 0;
}
```

**11. Wide String Trimming:**

```c
#include <wctype.h>
#include <wchar.h>

int main() {
  wchar_t str[] = L" Hello, world! ";
  wcsptrim(str);
  printf("Trimmed string: %ls\n", str);
  return 0;
}
```

**12. Wide String Reversal:**

```c
#include <wctype.h>
#include <wchar.h>

int main() {
  wchar_t str[] = L"Hello, world!";
  wcsrtombs(str, str, wcslen(str));
  printf("Reversed string: %ls\n", str);
  return 0;
}
```

**13. Wide String Interpolation:**

```c
#include <wctype.h>
#include <wchar.h>

int main() {
  wchar_t str[100];
  size_t size = wcsftime(str, 100, L"%Y-%m-%d %H:%M:%S", gmtime(NULL));
  printf("Current time: %ls\n", str);
  return 0;
}
```

**14. Character Code Conversion:**

```c
#include <wctype.h>
#include <wchar.h>

int main() {
  wint_t wc = L'€';
  char mb = wctomb(NULL, wc);
  printf("Multibyte representation: %c\n", mb);
  return 0;
}
```

**15. Wide String Length:**

```c
#include <wctype.h>
#include <wchar.h>

int main() {
  const wchar_t *str = L"Hello, world!";
  size_t len = wcslen(str);
  printf("String length: %zu\n", len);
  return 0;
}
```

**16. Wide String Concatenation:**

```c
#include <wctype.h>
#include <wchar.h>

int main() {
  wchar_t str1[] = L"Hello", str2[] = L" world!";
  wcscat(str1, str2);
  printf("Concatenated string: %ls\n", str1);
  return 0;
}
```

**17. Wide String Copying:**

```c
#include <wctype.h>
#include <wchar.h>

int main() {
  wchar_t str1[] = L"Hello", str2[6];
  wcscpy(str2, str1);
  printf("Copied string: %ls\n", str2);
  return 0;
}
```

**18. Wide String Comparison:**

```c
#include <wctype.h>
#include <wchar.h>

int main() {
  const wchar_t *str1 = L"Hello", *str2 = L"HELLO";
  int cmp = wcscmp(str1, str2);
  printf("Comparison result: %d\n", cmp);
  return 0;
}
```

**19. Wide String Searching:**

```c
#include <wctype.h>
#include <wchar.h>

int main() {
  const wchar_t *str = L"Hello, world!";
  wchar_t *result = wcsstr(str, L"world");
  printf("Index of substring: %d\n", result - str);
  return 0;
}
```

**20. Wide String Replacement:**

```c
#include <wctype.h>
#include <wchar.h>

int main() {
  wchar_t str[] = L"Hello, world!";
  wcscat(str, L" replaced");
  printf("Replaced string: %ls\n", str);
  return 0;
}
```

**21. Wide String Splitting:**

```c
#include <wctype.h>
#include <wchar.h>

int main() {
  const wchar_t *str = L"This is a sample string";
  wchar_t *token = wcstok(wstr, L" ");
  while (token != NULL) {
    printf("%ls\n", token);
    token = wcstok(NULL, L" ");
  }
  return 0;
}
```

**22. Wide String Padding:**

```c
#include <wctype.h>
#include <wchar.h>

int main() {
  wchar_t str[100];
  swprintf(str, 100, L"%10s", L"Hello");
  printf("Padded string: %ls\n", str);
  return 0;
}
```

**23. Wide String Centering:**

```c
#include <wctype.h>
#include <wchar.h>

int main() {
  wchar_t str[100];
  swprintf(str, 100, L"%-10s", L"Hello");
  printf("Centered string: %ls\n", str);
  return 0;
}
```
