Я пытаюсь токенизировать строку и поместить ее в двумерный массив, пока я придумал это, но я чувствую, что я далек:
/**
* Function to tokenize an input line into seperate tokens
*
* The first arg is the line to be tokenized and the second arg points to
* a 2-dimentional string array. The number of rows of this array should be
* at least MAX_TOKENS_PER_LINE size, and the number of columns (i.e., length
* of each string should be at least MAX_TOKEN_SIZE)
*
* Returns 0 on success and negative number on failure
*/
int __tokenize(char *line, char tokens[][MAX_TOKEN_SIZE], int *num_tokens){
char *tokenPtr;
tokenPtr = strtok(line, " \t");
for(int j =0; j<MAX_TOKEN_SIZE; j++){
while(tokenPtr != NULL){
if(!(tokens[][j] = tokenPtr)){return -1;}
num_tokens++;
tokenPtr = strtok(NULL, " \t");
}
}
return 0;
}
strtok
принимает 2 аргумента. Какую систему/язык (с 3-аргументомstrtok
) вы используете? - person pmg   schedule 04.05.2011strtok(INPUT_STRING, DELIMITERS)
), а затем в цикле захват дополнительных фрагментов (strtok(NULL, DELIMITERS)
). - person pmg   schedule 04.05.2011strtok
иstrsep
— документы — ваши друзья. - person nmichaels   schedule 04.05.2011tokenPtr = strtok(NULL, " \t");
. Вы просто передаете ему массив символов, которые хотите использовать в качестве разделителей. - person John Leehey   schedule 04.05.2011