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

post the declaration of variable word. It should be

char word[some_value];

or
char *word;

post your code

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.

>>Ah I know the answer, he didn't.
Your probably right -- he has not written a function that calls getCount() yet.

i finally got it right my mistake was here:

int getCount(char word)

it should be:

int getCount(char word[30])
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.