【发布时间】:2015-03-10 17:02:14
【问题描述】:
这个问题我需要帮助,我似乎无法解决它。 我不断收到此错误
error: incompatible types when assigning to type ‘char[21]’ from type ‘char *’
WordList[i].word = token;
代码
#include <stdio.h>
#include <string.h>
struct myWord{
char word[21];
int Length;
};
int main(){
struct myWord WordList[20];
char myString[] = "the cat in the hat jumped over the lazy fox";
char *token;
int i;
while((token = strtok(myString, " ")) != NULL){
for(i=0; i<20; i++){
WordList[i].word = token;
WordList[i].Length = strlen(token);
}
}
for(i=0; i<20; i++)
printf("%s\t%d\n", WordList[i].word, WordList[i].Length);
}
【问题讨论】:
-
我投票结束这个问题,因为“请快速帮助”