asdf asdf - 2 months ago 7
C Question

Parsing a 3 word string in C

I have a text with this pattern :

command arg1 arg2
.
How can I extract
arg1
and
arg2
and store them in 2 variables?
I know that SO is not a code writing service, but i'm kind off running on a deadline and the results aren't helping.

Answer

You can use sscanf to achieve this

#include <stdio.h>

char command[64];
char arg1[64];
char arg2[64];

sscanf("a b c", "%s %s %s", command, arg1, arg2);

Now command equals "a", arg1 equals "b" and arg2 equals "c"