I have the current C code:
#include <string.h> // strdup
#include <stdio.h> // printf
#include <stdlib.h> // free
int main(int argc, char *argv[])
{
const char isostr[] = "\\ISO 2022 IR 13\\ISO 2022 IR 87";
char *query = strdup( isostr );
char *token;
char *str1;
char *saveptr1;
const char delim[] = "\\";
for (str1 = query; ; str1 = NULL)
{
token = strtok_r(str1, delim, &saveptr1);
if (token == NULL)
break;
printf(" --> %s\n", token);
}
free( query );
return 0;
}
However it is returning:
--> ISO 2022 IR 13
--> ISO 2022 IR 87
while I would need to return:
--> [null/empty]
--> ISO 2022 IR 13
--> ISO 2022 IR 87
strtok_r does not seems to make any difference in between the string "AA\BB\CC" and "AA\BB\CC\" or "\AA\BB\\CC".