?
Solved

What's today's WEEKDAY name and other general ?'s

Posted on 2006-04-19
3
Medium Priority
?
255 Views
Last Modified: 2010-04-01
Hello EE EXPERTS!

Can you help me out? Stuck again.

I am trying to set a variable depending upon which day of the week it is.

so far I have this:

      SYSTEMTIME systemtime;
      char TheTime[19];
      GetSystemTime( &systemtime );
      sprintf (TheTime, "%04d:%02d:%02d: %02d:%02d:%02d :%04d ",
            systemtime.wYear, systemtime.wMonth, systemtime.wDay, systemtime.wHour, systemtime.wMinute, systemtime.wSecond, systemtime.wMilliseconds);
      MessageBox(NULL, TheTime, "N o w", MB_OK);

but I need a switch statement, like:

case "Monday", "Tuesday", "Friday"
     mystruct.myvar = true;
case "Wednesday", "Thursday", "Saturday"
     mystruct.myvar =false;
default:
      mystruct.myvar =false;

Man, I get so close to thinking I have a good handle on this, then the simplest of tasks proves to be quite the challenge!

How do I extract the weekday name from my code above?

AND LASTLY please explain something to me , what are the "rules" for using strlen ?

How come it works with some strings and not others?

For instance, this code:

        int bRet;
      int iComputerNameLength;

      TCHAR  infoBuf[MAX_COMPUTERNAME_LENGTH+1];
      DWORD  bufCharCount = MAX_COMPUTERNAME_LENGTH+1;
 
      // Get and display the name of the computer.
      bufCharCount = MAX_COMPUTERNAME_LENGTH+1;
      bRet = GetComputerName( infoBuf, &bufCharCount );


why does if(lstrlenA(infoBuf)>=5){... work and not

strlen(infoBuf)?

I must be missing something here.... I can use some functions but not others???

THANKS!
0
Comment
Question by:edvinson
3 Comments
 
LVL 85

Assisted Solution

by:ozo
ozo earned 200 total points
ID: 16494233
switch(  systemtime.wDayOfWeek ){
case 1: case 2: case 5: { mystruct.myvar = true; } break;
case 3: case 4: case 6: { mystruct.myvar = false; } break;
default: { mystruct.myvar = false; } break;
}
0
 
LVL 12

Assisted Solution

by:AmigoJack
AmigoJack earned 200 total points
ID: 16495467
you should look at the win32.hlp or msdn doc how SYSTEMTIME is defined and that SYSTEMTIME.wDayOfWeek holds what youre looking for. a 0 is sunday, 1 is monday, 2 tuesday and so on. thats more useful than full names, because windows doesnt run in english languages only...
0
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 1600 total points
ID: 16498174
>>>> a 0 is sunday, 1 is monday, 2 tuesday ...

In C++ usually you would define an enum like that:

enum DayOfWeek { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, WEEKDAYS };

Then, you might have a static array for outputting names:

static char* daysOfWeek[WEEKDAYS] =
{
     "SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY",
};  

switch(  systemtime.wDayOfWeek )
{
   case MONDAY: case TUESDAY: case FRIDAY:
       mystruct.myvar = true;
       break;
   default:
       mystruct.myvar = false;
       break;
}

>>>> How come it works with some strings and not others?

The problem is TCHAR type. It's a typedef that is either a single byte or 'char' type (ANSI) or a double-byte or wchar_t type (UNICODE). The latter is the case if the macro _UNICODE was defined in your project settings.

strlen only accepts (const) char* type but not a wchar_t*.

The way out is to use _tcslen which is defined to fit to TCHAR type regardless whether it is a char or wchar_t

You may check the article "strlen, wcslen, _mbslen, _mbstrlen" in MSDN to learn more.

Regards, Alex

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question