1

I would like to split a wchar_t string defined using pointer to its constituent wchar_t characters in C. i.e, if wchar_t *wcs = L"बहन" , then the output should be ब ह न

I tried the below 2 code snippets, but failed to get the desired output.

(1)

wchar_t *input = L"बहन";
int i=0;
while (input[i] != L'\0') {
      printf("i = %d : %lc\n",wcslen(input), input[i]);
      i++;
}

(2) In this approach I was not sure about what was to be used to split the string using the wcstok function. Hence, I gave the argument as L"".

wchar_t *input = L"बहन";
wchar_t *token;
wchar_t *state;
for (token = wcstok(input, L"", &state);token != NULL;token = wcstok(NULL, L"", &state)) {
        printf("Here %d: %s\n",wcslen(token),token);
    }
Alan Stokes
  • 18,815
  • 3
  • 45
  • 64

0 Answers0