C编程 - 带TCHAR的枚举开关案例

C programming - enum switch case with TCHAR

I am doing a win32 program with C and I do not know how to do a enum and switch case with UNICODE. I receive from the client a named pipe with this structure

    typedef struct {
TCHAR UtilOrigem[10];
TCHAR Comando[3]; // Comando
TCHAR Argumento1[10];
}cmd;

cmd.comando have values "00", "01", "02" .....

And I want to do a switch case with cmd.comando.

Please help me. Thanks Carlos

Try this:

int val = _ttoi(cmd.comando);
switch (val)
{
case 0:
   ...
   break;
case 1:
   ...
   break;
case 2:
   ...
   break;
...
}

Or even simpler:

int val = 10*(cmd.comando[0]-L'0')+(cmd.comando[1]-L'0');
switch (val)
{
case 0:
   ...
   break;
case 1:
   ...
   break;
case 2:
   ...
   break;
...
}
If UNICODE is defined as the question suggests, '0' will need to be L'0'.
@AndrewMedico: I agree, thanks (was indeed wondering about it after adding the second option).
Thank you Barak Manos,
@cacc: You're welcome. Don't forget to accept the answer by clicking on the V next to it (if it solved your problem).
very grateful. It was the first time I put a question on this forum but now I consult a few years ago. @barakmanos