mirror of
https://github.com/janbodnar/Windows-API-examples.git
synced 2024-11-24 11:25:30 +00:00
Create winapi_string_types.c
This commit is contained in:
parent
2a0bf7c11b
commit
630449cb64
61
strings/winapi_string_types.c
Normal file
61
strings/winapi_string_types.c
Normal file
@ -0,0 +1,61 @@
|
||||
#include <windows.h>
|
||||
#include <wchar.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
int wmain(void) {
|
||||
|
||||
wchar_t str[] = L"7 white, 3 red roses.\n";
|
||||
|
||||
int alphas = 0;
|
||||
int digits = 0;
|
||||
int spaces = 0;
|
||||
int puncts = 0;
|
||||
int contrs = 0;
|
||||
|
||||
int size = lstrlenW(str);
|
||||
WORD types[size];
|
||||
ZeroMemory(types, size);
|
||||
|
||||
bool rv = GetStringTypeW(CT_CTYPE1, str, size, types);
|
||||
|
||||
if (!rv) {
|
||||
|
||||
wprintf(L"Could not get character types (%ld)", GetLastError());
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
for (int i=0; i<size; i++) {
|
||||
|
||||
if (types[i] & C1_ALPHA) {
|
||||
|
||||
alphas++;
|
||||
}
|
||||
|
||||
if (types[i] & C1_DIGIT) {
|
||||
|
||||
digits++;
|
||||
}
|
||||
|
||||
if (types[i] & C1_SPACE) {
|
||||
|
||||
spaces++;
|
||||
}
|
||||
|
||||
if (types[i] & C1_PUNCT) {
|
||||
|
||||
puncts++;
|
||||
}
|
||||
|
||||
if (types[i] & C1_CNTRL) {
|
||||
|
||||
contrs++;
|
||||
}
|
||||
}
|
||||
|
||||
wprintf(L"There are %ld letter(s), %ld digit(s), "
|
||||
L"%ld space(s), %ld punctuation character(s), "
|
||||
L"and %ld control character(s)\n", alphas, digits,
|
||||
spaces, puncts, contrs);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user