0

I am trying to move my char pointer along my char array (a string), it doesn't work and I don't understand why.

My char array looks like this "5,true,-12,..."

Here is my code :

local_length = get_param_length(jump_next_param(param));
  • local length is the param's length (without the comma)
  • param is the string i want to parse

With the exemple I gave, before the line I wrote, local_length = 1 (5 length). After the line I wrote, local_length = 4 (true length).

But param still pointing to 5 and I want it pointing to t

Here is the code of jump_next_param():

static char* jump_next_param(char *param){
    uint32_t jump_length = get_param_length(param);
    param += jump_length + 1;
return param;}
Clément
  • 37
  • 5

1 Answers1

0

What you really have here is an XY problem. You want help parsing individual items out of a comma-delimited list. If you don't have to worry about quote-surrounded strings containing commas, you can just use strchr for that:

char *list = "first,second,third,fourth,fifth";
char *p = list;
char *q = list;

do
{
    p = strchr(q, ',');
    printf("%.*s\n", (ptrdiff_t)(p - q), q);
    q = p;
    p++, q++;
}
while (p != NULL);
Govind Parmar
  • 20,656
  • 7
  • 53
  • 85