我遇到了strtok函數的問題。我不斷收到'巴士錯誤'。我寫了一個函數來返回一行中的所有單詞。有人能指出我的錯誤嗎?C編程strtok
注意:我用高級語言
void extract_words(char tokens[WORD_MAX][WORD_LEN], char* line, int* sizePtr)
{
printf("in extract words"); //for debugging
char* chPtr = NULL;
chPtr = strtok(line, " ");
int size = 1; //words has one element
while(chPtr != NULL)
{
strcpy(tokens[size++], chPtr);
chPtr = strtok(NULL, " "); //continue to tokenize the string
}
*sizePtr = size;
}
提前感謝!
當你調用它時,你可能沒有提供'sizePtr'的有效地址。 – 2012-02-23 05:57:00
這是我如何使用sizePtr:int size; int * sizePtr = &size; – CodeKingPlusPlus 2012-02-23 06:00:21
也許你試圖傳遞一個字符串作爲行參數? – 2012-02-23 06:03:16