Hi everyone,
I'm new to C programming and trying to do something.
I have a character string. Its just numbers delimited by a comma.
Example.
unsigned char string[] = {1,2,3,4,5,6};
I need to count how many items there are. This is for a function that needs to know how many items its getting. There are more strings so Its not a fixed value. And I can't just use a maximum possible. I know I need to use string.h functions... my understanding is that I would do something like:
get length of whole string.
look for first comma
add to counter variable.
look for next, repeat till end.
can some one give me an example of the code?
or of there is an easier way I would appritiate any help.
Thanks.
I'm new to C programming and trying to do something.
I have a character string. Its just numbers delimited by a comma.
Example.
unsigned char string[] = {1,2,3,4,5,6};
I need to count how many items there are. This is for a function that needs to know how many items its getting. There are more strings so Its not a fixed value. And I can't just use a maximum possible. I know I need to use string.h functions... my understanding is that I would do something like:
get length of whole string.
look for first comma
add to counter variable.
look for next, repeat till end.
can some one give me an example of the code?
or of there is an easier way I would appritiate any help.
Thanks.
Comment