C programming - enum switch case with TCHAR
-
21-12-2019 - |
Question
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
Solution
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;
...
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow