parsing string off a configuration using strtok in C

Posted by Jessica on Stack Overflow See other posts from Stack Overflow or by Jessica
Published on 2010-06-17T18:45:16Z Indexed on 2010/06/17 18:53 UTC
Read the original article Hit count: 315

Filed under:
|
|

in the configuration file i have entries similar to this one:

filepath = c:\Program Files\some value

Where the path can contain spaces and there are no quotes on that string. I tried parsing this with strtok like:

char *option;
char *value;

value = strtok(line, " =");
strcpy(option, value);
value = strtok(NULL, " =");

where line is the line I am reading from the file, option will contain the left side of the equal (filepath) and value will contain the right side (c:\program files\some value). I know, it's poor coding, but I haven't found something better. sorry... In any case, for those options where there's no space in the right side it works great, but in those containing spaces it only return the string until the 1st space: c:\Program.

Is there any other way to do this?

Code is appreciated. Jessica

© Stack Overflow or respective owner

Related posts about c

    Related posts about string