asdf asdf - 7 months ago 35
C Question

Parsing a 3 word string in C

I have a text with this pattern :

command arg1 arg2
How can I extract
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.


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"