Skip to content

Commit 1e11747

Browse files
committed
+ winapi_string_compare, fillbuffer, types
1 parent 598bbb8 commit 1e11747

3 files changed

Lines changed: 111 additions & 0 deletions

File tree

‎winapi_string_compare.c‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <windows.h>
2+
#include <wchar.h>
3+
4+
#define STR_EQUAL 0
5+
6+
int wmain()
7+
{
8+
wchar_t *s1 = L"Strong";
9+
wchar_t *s2 = L"strong";
10+
11+
if(lstrcmpW(s1, s2) == STR_EQUAL)
12+
{
13+
wprintf(L"%ls and %ls are equal\n", s1, s2);
14+
}
15+
else
16+
{
17+
wprintf(L"%ls and %ls are not equal\n", s1, s2);
18+
}
19+
20+
wprintf(L"When applying case insensitive comparison:\n");
21+
22+
if(lstrcmpiW(s1, s2) == STR_EQUAL)
23+
{
24+
wprintf(L"%ls and %ls are equal\n", s1, s2);
25+
}
26+
else
27+
{
28+
wprintf(L"%ls and %ls are not equal\n", s1, s2);
29+
}
30+
31+
return 0;
32+
}

‎winapi_string_fillbuffer.c‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <windows.h>
2+
#include <wchar.h>
3+
4+
#pragma comment(lib, "user32.lib")
5+
6+
int wmain()
7+
{
8+
SYSTEMTIME st = {0};
9+
wchar_t buf[128] = {0};
10+
11+
GetLocalTime(&st);
12+
wsprintfW(buf, L"Today is %lu.%lu.%lu\n", st.wDay, st.wMonth, st.wYear);
13+
wprintf(buf);
14+
15+
return 0;
16+
}

‎winapi_string_types.cpp‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#include <windows.h>
2+
#include <wchar.h>
3+
#include <stdbool.h>
4+
5+
int wmain()
6+
{
7+
wchar_t str[] = L"7 white, 3 red roses.\n";
8+
9+
int alphas = 0;
10+
int digits = 0;
11+
int spaces = 0;
12+
int puncts = 0;
13+
int contrs = 0;
14+
15+
int size = lstrlenW(str);
16+
//WORD types[size];
17+
WORD *types = new WORD[size];
18+
ZeroMemory(types, size);
19+
20+
bool rv = GetStringTypeW(CT_CTYPE1, str, size, types);
21+
if(!rv)
22+
{
23+
wprintf(L"Could not get character types (%ld)", GetLastError());
24+
return EXIT_FAILURE;
25+
}
26+
27+
for(int i=0; i<size; i++)
28+
{
29+
if(types[i] & C1_ALPHA)
30+
{
31+
alphas++;
32+
}
33+
34+
if(types[i] & C1_DIGIT)
35+
{
36+
digits++;
37+
}
38+
39+
if(types[i] & C1_SPACE)
40+
{
41+
spaces++;
42+
}
43+
44+
if(types[i] & C1_PUNCT)
45+
{
46+
puncts++;
47+
}
48+
49+
if(types[i] & C1_CNTRL)
50+
{
51+
contrs++;
52+
}
53+
}
54+
55+
delete[] types;
56+
57+
wprintf(L"There are %ld letter(s), %ld digit(s), "
58+
L"%ld space(s), %ld punctuation character(s), "
59+
L"and %ld control character(s)\n", alphas, digits,
60+
spaces, puncts, contrs);
61+
62+
return 0;
63+
}

0 commit comments

Comments
 (0)