Home/Support/Support Forum/parsing strings in dynamic C
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

parsing strings in dynamic C

0 votes
I am trying to parse a string in dynamic C. The string is the response of a valco valve to a position query. The string is usually of the form:

"2 Position is = xx"

I can split this string to only return the "xx" in C but not in dynamic C. Here is the code I am currently using:

#include <stdio.h>
#include <string.h>

int main ()
{
char actualpos[] ="2 Position is = 13";
char * valco2pos;
valco2pos = strtok(actualpos,"=");
valco2pos = strtok (NULL, "=");

if (valco2pos[0] == ' ')
memmove(valco2pos, valco2pos+1, strlen(valco2pos));

printf("%s\n", valco2pos);

}

Any advice?
asked Jul 6, 2016 in Rabbit Software by emorgan New to the Community (0 points)

Please log in or register to answer this question.

1 Answer

0 votes
When I run that code with Dynamic C 10.72A, I see "13". What happens when you run it? Did you run your tests with some other code or with an older version of Dynamic C?

Here's a version that doesn't modify the source string:
Code:
#include <stdio.h> #include <string.h> const char *parse_valco(const char *src) { src = strchr(src, '='); // find the equal sign if (src != NULL) { ++src; // point past the equals sign while (*src == ' ') { ++src; // skip over any spaces } } return src; } int main () { char actualpos[] = "2 Position is = 13"; const char *valco2pos; valco2pos = parse_valco(actualpos); if (valco2pos == NULL) { printf("couldn't find equal sign\n"); } else { printf("%s\n", valco2pos); } }
answered Jul 7, 2016 by TomCollins Veteran of the Digi Community (1,872 points)
...