ユーザーが「print 1 2」や「open file1」などのコマンドを入力する小さなプログラムを作成しています。ユーザーがやりたいことを処理するために、を使用してすべてのスペースでユーザー入力を分割しようとしていますstrtok
。私の問題は、次のコードの場合です。
void tokenize(char string[100],char tokenized[10][MAX_CHARS]){
char delims[] = " "; /*Delimitere is a space so tokenize when a space occurs*/
char *result = NULL;
int count = 0;
result=strtok(string,delims); /*Tokenize the string*/
while(result!=NULL && count<10){
tokenized[count++][MAX_CHARS] = result; /* This is where I get the error */
result= strtok(NULL,delims);
}
}
次のエラーが表示されます。
stringapi.c: In function ‘tokenize’:
stringapi.c:33:33: warning: assignment makes integer from pointer without a cast [enabled by default]
私はしばらくこの問題を解決しようとしてきましたが、うまくいきませんでした。
試しtokenized[count++] = result;
ましたが、次のエラーが表示されます。
stringapi.c:33:22: error: incompatible types when assigning to type ‘char[80]’ from type ‘char *’
私の最終的な目標は、ユーザーが「open newfile.txt」と入力した場合に、
array[0]
開いている配列array[1]
と newfile.txt が必要であり、それに応じて処理できるようにすることです。