I was wondering how you could take 1 string, split it into 2 with a delimiter, such as space, and assign the 2 parts to 2 separate strings. I\'ve tried using strtok()
strtok()
char *line = strdup("user name"); // don't do char *line = "user name"; see Note char *first_part = strtok(line, " "); //first_part points to "user" char *sec_part = strtok(NULL, " "); //sec_part points to "name"
Note: strtok modifies the string, so don't hand it a pointer to string literal.
strtok