#include <windows.h>
#include <wchar.h>
#include <stdbool.h>
int wmain1(void){
char * name="Jane";
wchar_t * town = L"Bratislava";
wprintf(L"The length of the string is %d\n", lstrlenA(name));
wprintf(L"The town string length is %d \n", lstrlenW(town));
return 0;
}
int main1(void){
wchar_t *s1 = L"ZetCode, ";
wchar_t *s2 = L"tutorials ";
wchar_t *s3 = L"for ";
wchar_t *s4 = L"programmers.\n";
int len = lstrlenW(s1) +
lstrlenW(s2) +
lstrlenW(s3) +
lstrlenW(s4);
wchar_t buff[len+1];
lstrcpyW(buff,s1);
lstrcatW(buff,s2);
lstrcatW(buff,s3);
lstrcatW(buff,s4);
wprintf(buff);
return 0;
}
#pragma comment(lib, "User32.lib")
int wmain2(void){
wchar_t str[] = L"Europa";
CharLowerW(str);
wprintf(L"%ls\n",str);
CharUpperW(str);
wprintf(L"%ls\n",str);
return 0;
}
#define STR_EQUAL 0
int wmain3(void){
wchar_t *s1 = L"Strong";
wchar_t *s2 = L"strong";
if (lstrcmpW(s1,s2) == STR_EQUAL){
wprintf(L"%ls and %ls are equal.\n",s1,s2);
}else{
wprintf(L"%ls and %ls are not equal.\n",s1,s2);
}
wprintf(L"When applying case sensitive comparison:\n");
if(lstrcmpiW(s1,s2)==STR_EQUAL){
wprintf(L"%ls and %ls are equal.\n",s1,s2);
}else{
wprintf(L"%ls and %ls are not equal.\n",s1,s2);
}
return 0;
}
int wmain4(void){
SYSTEMTIME st;
wchar_t buff[50];
GetLocalTime(&st);
wsprintfW(buff, L"Today is %lu/%lu/%lu.\n", st.wDay,st.wMonth,st.wYear);
wprintf(buff);
return 0;
}
int wmain5(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];
BOOL rv = GetStringTypeW(CT_CTYPE1, str, size, types);
if(!rv){
wprintf(L"Couldn't 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 letters(s), %ld digit(s), %ld space(s), %ld punctuation character(s), "
L"and %ld controls character(s)\n", alphas, digits, spaces, puncts, contrs);
return 0;
}
int wmain6(void){
wchar_t str1[] = L"There are 15 pines.";
wprintf(L"The length of the string is %ld characters.\n", wcslen(str1));
wchar_t buf[20];
wcscpy(buf, L"Wuthering ");
wcscat(buf, L"Heights.\n");
wprintf(buf);
if(wcscmp(L"rain",L"rainy")==STR_EQUAL){
wprintf(L"rain and rainy are equal strings.\n");
}else{
wprintf(L"rain and rainy are not equal strings.\n");
}
return 0;
}
int wmain7(void){
SYSTEMTIME lt;
GetLocalTime(<);
wprintf(L"\nThe local time is : %02d:%02d:%02d\n",lt.wHour, lt.wMinute,lt.wSecond);
return 0;
}
int wmain8(void){
SYSTEMTIME st;
GetSystemTime(&st);
wprintf(L"\nThe system time is : %02d:%02d:%02d\n",st.wHour,st.wMinute,st.wSecond);
return 0;
}
int wmain9(void){
SYSTEMTIME st;
GetLocalTime(&st);
wprintf(L"\nToday is : %d-%02d-%02d\n",st.wYear,st.wMonth,st.wDay);
return 0;
}
bool isLeapYear(int);
int wmain10(void){
int years[] = {2000,2002,2004,2008,2012,1900,1800,1600,1200,1000};
int size = sizeof(years)/sizeof(int);
for(int i=0;i<size;i++){
if(isLeapYear(years[i])){
wprintf(L"\n%ld is a leap year\n",years[i]);
}else{
wprintf(L"\n%ld is not a leap year\n",years[i]);
}
}
return 0;
}
bool isLeapYear(int year){
if((year % 100 == 0) && (year % 400 == 0)){
return true;
}
if((year % 4 == 0) && (year % 100 != 0)){
return true;
}
return false;
}
int wmain11(void){
DWORD tc = GetTickCount();
short seconds = tc / 1000 % 60;
short minutes = tc / 1000 / 60 % 60;
short hours = tc / 1000 / 60 / 60 % 24;
short days = tc / 1000 / 60 / 60 / 24 % 7;
short weeks = tc / 1000 / 60 / 60 / 24 / 7 % 52;
wprintf(L"\nComputer has been running for : ");
if(weeks > 0 && weeks !=1){
wprintf(L"%hi weeks ",weeks);
}else if(weeks==1){
wprintf(L"1 week ");
}
if(days > 0 && days !=1){
wprintf(L"%hi days ",days);
}else if(days==1){
wprintf(L"1 day ");
}
if(hours > 0 && hours !=1){
wprintf(L"%hi hours ",hours);
}else if(hours==1){
wprintf(L"1 hour ");
}
if(minutes > 0 && minutes != 1){
wprintf(L"%hi minutes ",minutes);
}else if(minutes==1){
wprintf(L"1 minute");
}
wprintf(L"and %hi seconds.\n", seconds);
return 0;
}
int wmain12(void){
SYSTEMTIME st;
wchar_t *dn[] = {L"Sunday", L"Monday", L"Tuesday", L"Wednesday", L"Thursday", L"Friday", L"Saturday", };
GetLocalTime(&st);
wprintf(L"\nToday is %ls\n", dn[st.wDayOfWeek]);
return 0;
}
int wmain13(void){
FILETIME ft;
GetSystemTimeAsFileTime(&ft);
LARGE_INTEGER li;
li.LowPart = ft.dwLowDateTime;
li.HighPart = ft.dwHighDateTime;
long long int hns = li.QuadPart;
wprintf(L"\n%lli hundreds of nanoseconds have elapsed since Windows API epoch.\n", hns);
return 0;
}
int wmain14(void){
FILETIME ft1;
FILETIME ft2;
SYSTEMTIME st = {0};
LARGE_INTEGER li1;
LARGE_INTEGER li2;
st.wYear = 2014;
st.wMonth = 12;
st.wDay = 25;
bool r = SystemTimeToFileTime(&st, &ft1);
if(!r){
wprintf(L"\nFailed to convert system time to file time\n %d",GetLastError());
return 1;
}
GetSystemTimeAsFileTime(&ft2);
li1.LowPart = ft1.dwLowDateTime;
li1.HighPart = ft1.dwHighDateTime;
li2.LowPart = ft2.dwLowDateTime;
li2.HighPart = ft2.dwHighDateTime;
long long int dif = li1.QuadPart - li2.QuadPart;
int daysToXmas = dif / 10000000L /60 / 60 / 24;
if(daysToXmas == 1){
wprintf(L"\nThere is one day until Xmas.\n");
}else if(daysToXmas == 0){
wprintf(L"\nToday is Xmas.\n");
}else {
wprintf(L"\nThere are %d days until Xmas.\n",daysToXmas);
}
return 0;
}
int wmain15(void){
SYSTEMTIME st1 = {0};
SYSTEMTIME st2 = {0};
FILETIME ft1;
FILETIME ft2;
st1.wYear = 2012;
st1.wMonth = 4;
st1.wDay = 12;
st2.wYear = 2012;
st2.wMonth = 5;
st2.wDay = 12;
bool r1 = SystemTimeToFileTime(&st1, &ft1);
if(!r1){
wprintf(L"\nFailed to convert SYSTEMTIME to FILETIME. %d\n", GetLastError());
return 1;
}
bool r2 = SystemTimeToFileTime(&st2, &ft2);
if(!r2){
wprintf(L"\nFailed to convert SYSTEMTIME to FILETIME. %d\n",GetLastError());
return 1;
}
short ct = CompareFileTime(&ft1, &ft2);
if(ct== -1){
wprintf(L"\n4/12/2012 comes before 5/12/2012.\n");
}else if(ct == 0){
wprintf(L"\n4/12/2012 is equal to 5/12/2012.\n");
}else if(ct == 1){
wprintf(L"\n4/12/2012 comes after 5/12/2012.\n");
}
return 0;
}
#include <wchar.h>
#include <stdbool.h>
int wmain1(void){
char * name="Jane";
wchar_t * town = L"Bratislava";
wprintf(L"The length of the string is %d\n", lstrlenA(name));
wprintf(L"The town string length is %d \n", lstrlenW(town));
return 0;
}
int main1(void){
wchar_t *s1 = L"ZetCode, ";
wchar_t *s2 = L"tutorials ";
wchar_t *s3 = L"for ";
wchar_t *s4 = L"programmers.\n";
int len = lstrlenW(s1) +
lstrlenW(s2) +
lstrlenW(s3) +
lstrlenW(s4);
wchar_t buff[len+1];
lstrcpyW(buff,s1);
lstrcatW(buff,s2);
lstrcatW(buff,s3);
lstrcatW(buff,s4);
wprintf(buff);
return 0;
}
#pragma comment(lib, "User32.lib")
int wmain2(void){
wchar_t str[] = L"Europa";
CharLowerW(str);
wprintf(L"%ls\n",str);
CharUpperW(str);
wprintf(L"%ls\n",str);
return 0;
}
#define STR_EQUAL 0
int wmain3(void){
wchar_t *s1 = L"Strong";
wchar_t *s2 = L"strong";
if (lstrcmpW(s1,s2) == STR_EQUAL){
wprintf(L"%ls and %ls are equal.\n",s1,s2);
}else{
wprintf(L"%ls and %ls are not equal.\n",s1,s2);
}
wprintf(L"When applying case sensitive comparison:\n");
if(lstrcmpiW(s1,s2)==STR_EQUAL){
wprintf(L"%ls and %ls are equal.\n",s1,s2);
}else{
wprintf(L"%ls and %ls are not equal.\n",s1,s2);
}
return 0;
}
int wmain4(void){
SYSTEMTIME st;
wchar_t buff[50];
GetLocalTime(&st);
wsprintfW(buff, L"Today is %lu/%lu/%lu.\n", st.wDay,st.wMonth,st.wYear);
wprintf(buff);
return 0;
}
int wmain5(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];
BOOL rv = GetStringTypeW(CT_CTYPE1, str, size, types);
if(!rv){
wprintf(L"Couldn't 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 letters(s), %ld digit(s), %ld space(s), %ld punctuation character(s), "
L"and %ld controls character(s)\n", alphas, digits, spaces, puncts, contrs);
return 0;
}
int wmain6(void){
wchar_t str1[] = L"There are 15 pines.";
wprintf(L"The length of the string is %ld characters.\n", wcslen(str1));
wchar_t buf[20];
wcscpy(buf, L"Wuthering ");
wcscat(buf, L"Heights.\n");
wprintf(buf);
if(wcscmp(L"rain",L"rainy")==STR_EQUAL){
wprintf(L"rain and rainy are equal strings.\n");
}else{
wprintf(L"rain and rainy are not equal strings.\n");
}
return 0;
}
int wmain7(void){
SYSTEMTIME lt;
GetLocalTime(<);
wprintf(L"\nThe local time is : %02d:%02d:%02d\n",lt.wHour, lt.wMinute,lt.wSecond);
return 0;
}
int wmain8(void){
SYSTEMTIME st;
GetSystemTime(&st);
wprintf(L"\nThe system time is : %02d:%02d:%02d\n",st.wHour,st.wMinute,st.wSecond);
return 0;
}
int wmain9(void){
SYSTEMTIME st;
GetLocalTime(&st);
wprintf(L"\nToday is : %d-%02d-%02d\n",st.wYear,st.wMonth,st.wDay);
return 0;
}
bool isLeapYear(int);
int wmain10(void){
int years[] = {2000,2002,2004,2008,2012,1900,1800,1600,1200,1000};
int size = sizeof(years)/sizeof(int);
for(int i=0;i<size;i++){
if(isLeapYear(years[i])){
wprintf(L"\n%ld is a leap year\n",years[i]);
}else{
wprintf(L"\n%ld is not a leap year\n",years[i]);
}
}
return 0;
}
bool isLeapYear(int year){
if((year % 100 == 0) && (year % 400 == 0)){
return true;
}
if((year % 4 == 0) && (year % 100 != 0)){
return true;
}
return false;
}
int wmain11(void){
DWORD tc = GetTickCount();
short seconds = tc / 1000 % 60;
short minutes = tc / 1000 / 60 % 60;
short hours = tc / 1000 / 60 / 60 % 24;
short days = tc / 1000 / 60 / 60 / 24 % 7;
short weeks = tc / 1000 / 60 / 60 / 24 / 7 % 52;
wprintf(L"\nComputer has been running for : ");
if(weeks > 0 && weeks !=1){
wprintf(L"%hi weeks ",weeks);
}else if(weeks==1){
wprintf(L"1 week ");
}
if(days > 0 && days !=1){
wprintf(L"%hi days ",days);
}else if(days==1){
wprintf(L"1 day ");
}
if(hours > 0 && hours !=1){
wprintf(L"%hi hours ",hours);
}else if(hours==1){
wprintf(L"1 hour ");
}
if(minutes > 0 && minutes != 1){
wprintf(L"%hi minutes ",minutes);
}else if(minutes==1){
wprintf(L"1 minute");
}
wprintf(L"and %hi seconds.\n", seconds);
return 0;
}
int wmain12(void){
SYSTEMTIME st;
wchar_t *dn[] = {L"Sunday", L"Monday", L"Tuesday", L"Wednesday", L"Thursday", L"Friday", L"Saturday", };
GetLocalTime(&st);
wprintf(L"\nToday is %ls\n", dn[st.wDayOfWeek]);
return 0;
}
int wmain13(void){
FILETIME ft;
GetSystemTimeAsFileTime(&ft);
LARGE_INTEGER li;
li.LowPart = ft.dwLowDateTime;
li.HighPart = ft.dwHighDateTime;
long long int hns = li.QuadPart;
wprintf(L"\n%lli hundreds of nanoseconds have elapsed since Windows API epoch.\n", hns);
return 0;
}
int wmain14(void){
FILETIME ft1;
FILETIME ft2;
SYSTEMTIME st = {0};
LARGE_INTEGER li1;
LARGE_INTEGER li2;
st.wYear = 2014;
st.wMonth = 12;
st.wDay = 25;
bool r = SystemTimeToFileTime(&st, &ft1);
if(!r){
wprintf(L"\nFailed to convert system time to file time\n %d",GetLastError());
return 1;
}
GetSystemTimeAsFileTime(&ft2);
li1.LowPart = ft1.dwLowDateTime;
li1.HighPart = ft1.dwHighDateTime;
li2.LowPart = ft2.dwLowDateTime;
li2.HighPart = ft2.dwHighDateTime;
long long int dif = li1.QuadPart - li2.QuadPart;
int daysToXmas = dif / 10000000L /60 / 60 / 24;
if(daysToXmas == 1){
wprintf(L"\nThere is one day until Xmas.\n");
}else if(daysToXmas == 0){
wprintf(L"\nToday is Xmas.\n");
}else {
wprintf(L"\nThere are %d days until Xmas.\n",daysToXmas);
}
return 0;
}
int wmain15(void){
SYSTEMTIME st1 = {0};
SYSTEMTIME st2 = {0};
FILETIME ft1;
FILETIME ft2;
st1.wYear = 2012;
st1.wMonth = 4;
st1.wDay = 12;
st2.wYear = 2012;
st2.wMonth = 5;
st2.wDay = 12;
bool r1 = SystemTimeToFileTime(&st1, &ft1);
if(!r1){
wprintf(L"\nFailed to convert SYSTEMTIME to FILETIME. %d\n", GetLastError());
return 1;
}
bool r2 = SystemTimeToFileTime(&st2, &ft2);
if(!r2){
wprintf(L"\nFailed to convert SYSTEMTIME to FILETIME. %d\n",GetLastError());
return 1;
}
short ct = CompareFileTime(&ft1, &ft2);
if(ct== -1){
wprintf(L"\n4/12/2012 comes before 5/12/2012.\n");
}else if(ct == 0){
wprintf(L"\n4/12/2012 is equal to 5/12/2012.\n");
}else if(ct == 1){
wprintf(L"\n4/12/2012 comes after 5/12/2012.\n");
}
return 0;
}