0

How can i split a string into 2 strings ?

Example Char[100]= "Xo = 100K" i want to split it to 2 string and save them into > Xo & 100K.

I could only save the first string, but i couldn't save the other one.

My code :-

while (ch[i]!= '=')
i++;
strncpy(var,ch,i);
  • 2
    For example using `strtok`. See this [question](http://stackoverflow.com/questions/9210528/split-string-with-delimiters-in-c) (but there are many others): – terence hill May 10 '17 at 09:00
  • 1
    `char var[100], value[100]; if(2 == sscanf(ch, "%s = %s", var, value)){ /* do stuff */}` – BLUEPIXY May 10 '17 at 09:16

1 Answers1

0

By using strtok function you are able to setup string of delimiters to function to create chunks from string.

By using " =" as delimiter you will get your result.

unalignedmemoryaccess
  • 7,246
  • 2
  • 25
  • 40