I basically want to take a single line of input from stdin, grab 'strings' (an array of char's separated by a space), and then place each 'string' into an array of char[]. I've already tried using fgets, getline, and strtok; I don't want to use outside libraries or anything that is unavailable to Unix. I've seen a lot of similar questions on here so I'm sorry if this has already been answered, but I can't find a straightforward, cut and dry way to do this.
Thanks, and I apologize if I've termed anything incorrectly, I am very much not used to C.
EDIT: Okay, so here's what I've tried most recently:
#include <string.h>
#include <stdio.h>
int main() {
const char str[80] = "This is a | test";
const char s[2] = " ";
char *token;
char arguments[10][50];
int i = 0;
/* get the first token */
token = strtok(str, s);
/* walk through other tokens */
while( token != NULL )
{
printf( " %s\n", token );
arguments[i] = token;
i++;
token = strtok(NULL, s);
}
return(0);
}
EDIT: Thanks Paul, for anyone with the same question as I had, I got it to work by changing the line that says:
arguments[i] = token;
to:
strcpy(arguments[i], token);