将令牌存储到数组中

Ein*_*ols 1 c arrays string

我需要将令牌存储到数组中.然后我想在句子中找到相同的标记.

int main()    
{
    int i=0;
    char* words[200];
    char text[200];

    printf("Enter one sentence \n ");
    gets(text);
    char *word = strtok(text, " ");

    while(word!=0)
    {
        words=malloc(strlen(word)+1);              
        strcpy(words[i++], word);
        printf("[%s]\n", word);
        word=strtok(NULL, " ,.!?");
    }

    getch();
    return 0;
} 
Run Code Online (Sandbox Code Playgroud)

我不知道为什么这个erorr-22不兼容的类型在void*中分配给char*[200]'如果我将单词改为单词[i] = malloc .....得到错误22无效转换为void*来char*'

然后我想知道如何从这个数组我可以比较这些令牌与strcmp.这是我的尝试,但看起来不起作用.

for (k=0; k<199; k++)
{
 for (j=k+1; j<200; j++)
  { 
             if (strcmp(words[k],words[j])==0) 
             {
             printf("equal words are %d",words);
             }
             else
             {
             printf("In this sentence aren't equal words");
             }
   }

} 
Run Code Online (Sandbox Code Playgroud)

clc*_*cto 5

代替

words = malloc( strlen( word ) + 1 );
Run Code Online (Sandbox Code Playgroud)

你需要获得正确的索引words并分配它.

words[i] = malloc( strlen( word ) + 1 );
Run Code Online (Sandbox Code Playgroud)

您没有尝试比较令牌.一旦你展示了你尝试过的东西(或者你尝试过之后),我们会帮助你.