我正在制作一个小程序,其中用户键入“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,然后我可以相应地处理。