Hello, my procedure should take a string and parse all all values separated by comma ',' and store them in objQueue[qid].filtValue array. This array is of wide-char type.
Code:
typedef
struct
{
char *name;
int filtValueCount;
wchar_t **filtValue;
} tQueueDef;
tQueueDef *objQueue;
/*
qid - identifier (not important now)
*s - pointer to parsed string
*len - lenght of the parsed string
*cnt - number of commas in the parsed string
*/
void parseFiltValues(int qid, char *s, int *len, int *cnt)
{
int i, j, k;
char *ptr, *tmp;
tmp = (char *)malloc((MSG_LENGTH) * sizeof(char));
printf("ParseFiltValues qid: %d, len: %d, cnt: %d\n", qid, *len, *cnt);
if (*len == 0)
return;
objQueue[qid].filtValueCount = *cnt;
objQueue[qid].filtValue = (wchar_t **)malloc(*cnt * sizeof(wchar_t *));
for (ptr = s, i = j = k = 0; i <= *len; i++, j++)
{
switch (s[i])
{
case ',':
case '}':
strncpy(tmp, ptr, j);
tmp[j] = '\0';
objQueue[qid].filtValue[k] = (wchar_t *)malloc(MSG_LENGTH * sizeof(wchar_t));
mbstowcs(objQueue[qid].filtValue[k], tmp, MSG_LENGTH);
printf("filt val (%d): %s<%d> <%d>\n", k, tmp, strlen(tmp), wcslen(objQueue[qid].filtValue[k]));
j = -1;
ptr = ss + i + 1;
k++;
break;
}
}
free(tmp);
}
So, for example, for input string {AA,AB,AD,AF}, the output should read:
filt val(0): AA<2> <2>
filt val(1): AB<2> <2>
filt val(2): AD<2> <2>
filt val(3): AF<2> <2>
It works well until an Eastern European character arrives to the input. For input string {AB,AC,AČ,AŇA,AF,AFŠ,AZ} the output reads, which means the mbstowcs does not convert it properly.
filt val(0): AA<2> <2>
filt val(1): AC<2> <2>
filt val(2): AČ<3> <1>
filt val(3): AŇA<4> <1>
filt val(4): AF<2> <2>
filt val(5): AFŠ<4> <2>
filt val(6): AZ<2> <2>
Can anyone help me here please? It's weird because I use similar funtionality elsewhere in the program and there it works just fine... Thanks a lot!