M
Marco Trapanese
Hi,
I'm trying to parse strings on an Atmel AVR device. I use the WinAVR C
Compiler (GCC)
The strings to parse are like this:
command -par0 -par1 -parn
I use strok_r function:
uint8_t sli_parseline(char *line, char *cmd, uint8_t *argc, char
argv[][ARG_MAX_LENGHT + 1]) {
const char delimiters[] = " -";
char *token;
char *ptr;
*argc = 0;
token = strtok_r(line, delimiters, &ptr);
strcpy(cmd, token);
for (; {
token = strtok_r(NULL, delimiters, &ptr);
if (token == NULL) break;
strcpy(argv[(*argc)++], token);
}
}
It works like a charm but strtok_r parses any char which is in the
delimiters string. Instead I want the delimiter is actually the string
itself. An example:
load -my file
leads to:
cmd = load
arg0 = my
arg1 = file
I want:
cmd = load
arg0 = my file
This because the delimiter actually is " -" and not either ' ' or '-'.
I'm sorry for my bad English I hope I can explain my problem.
Thanks in advance for any advice.
Marco / iw2nzm
I'm trying to parse strings on an Atmel AVR device. I use the WinAVR C
Compiler (GCC)
The strings to parse are like this:
command -par0 -par1 -parn
I use strok_r function:
uint8_t sli_parseline(char *line, char *cmd, uint8_t *argc, char
argv[][ARG_MAX_LENGHT + 1]) {
const char delimiters[] = " -";
char *token;
char *ptr;
*argc = 0;
token = strtok_r(line, delimiters, &ptr);
strcpy(cmd, token);
for (; {
token = strtok_r(NULL, delimiters, &ptr);
if (token == NULL) break;
strcpy(argv[(*argc)++], token);
}
}
It works like a charm but strtok_r parses any char which is in the
delimiters string. Instead I want the delimiter is actually the string
itself. An example:
load -my file
leads to:
cmd = load
arg0 = my
arg1 = file
I want:
cmd = load
arg0 = my file
This because the delimiter actually is " -" and not either ' ' or '-'.
I'm sorry for my bad English I hope I can explain my problem.
Thanks in advance for any advice.
Marco / iw2nzm