How can I split a TCHAR
into other variables?
Example:
TCHAR comando[50], arg1[50], arg2[50];
Mensagem msg;
_tcscpy(msg.texto, TEXT("MOVE 10 12"));
So, msg.texto
has the string "MOVE 10 12" and I want the variable comando[50]
to be "MOVE", the variable arg1
to be "10" and the variable arg2
to be "12". How can I do that?
Sorry for some possible English mistakes.
Thanks in advance!
SOLVED:
TCHAR *pch;
pch = _wcstok(msg.texto, " ");
_tcscpy(comando, pch);
pch = _wcstok(NULL, " ");
_tcscpy(arg1, pch);
pch = _wcstok(NULL, " ");
_tcscpy(arg2, pch);