i have this line of code and want to compare the word from the linked list with the one supplied by user.

the code is:

if (strcmp(p->word,word)==0)

and i am having this error:

passing `char' to argument 2 of `strcmp(const char *, const char *)' lacks a cast

herer is the code of the list:

struct doc_words
       {
        char words[30];
        struct doc_words *next;
       };

and the code of the function:

int getCount(char word)
    {

     int count=0;
     struct doc_words *p = head;
     while (p!=NULL)
           {
            if (strcmp(p->words,word)==0)
               {
                count++;
                p=p->next;
               }
            else
                {
                  p=p->next;
                }
     }
     return(count);
    }

word is a single char and strcmp takes char *. So you need to pas strcmp(p->words,&word) as second parameter. Are you shore: int getCount(char word) is right. Becouse there are more sense if it was int getCount(char * word)

>>int getCount(char word)

that should be like this

int getCount(char*  word)

>>strcmp(p->words,&word)
that won't work either. strcmp() expects a null-terminated string. Just passing the address of word does not make it null-terminated.

that won't work either. strcmp() expects a null-terminated string. Just passing the address of word does not make it null-terminated.

I agree, my mistake. I didn't think just saw that strcmp accepts pointer to char. But how did he pass the whole string inside one char?!?
Ah I know the answer, he didn't.

i finally got it right my mistake was here:

int getCount(char word)

it should be:

int getCount(char word[30])
This article has been dead for over six months. Start a new discussion instead.