| | |
how to compare stings in linked list
![]() |
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:
and i am having this error:
passing `char' to argument 2 of `strcmp(const char *, const char *)' lacks a cast
the code is:
C Syntax (Toggle Plain Text)
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
C Syntax (Toggle Plain Text)
char word[some_value]; or char *word;
herer is the code of the list:
and the code of the function:
C Syntax (Toggle Plain Text)
struct doc_words { char words[30]; struct doc_words *next; };
and the code of the function:
C Syntax (Toggle Plain Text)
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) Last edited by andor; Oct 23rd, 2006 at 8:50 am.
If you want to win, you must not loose (Alan Ford)
>>int getCount(char word)
that should be like this
>>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 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.
Ah I know the answer, he didn't.
Last edited by andor; Oct 23rd, 2006 at 9:19 am.
If you want to win, you must not loose (Alan Ford)
i finally got it right my mistake was here:
it should be:
C Syntax (Toggle Plain Text)
int getCount(char word)
it should be:
C Syntax (Toggle Plain Text)
int getCount(char word[30])
![]() |
Similar Threads
Other Threads in the C Forum
- Previous Thread: am i using fgets correctly? (Cprog)
- Next Thread: GTK code uses pointer for structs and not normal instances why?
Views: 2178 | Replies: 8
| Thread Tools | Search this Thread |
Tag cloud for C
#include api array arrays binary binarysearch bit build c++ c/c++ calling char character code coke command conversion convert database decimal directory dude dynamic error exec executable factorial fflush fgets file floatingpointvalidation fork function functions getline givemetehcodez grade graphics haiku help|help|help|help homework i/o include input insert int integer intmain() keyboard lazy line linked linkedlist linux list lists loop malloc matrix memory mysql no-effort output overwrite parallel path permutations pointer pointers problem process program programming read readfile recursion recursive recv reverse scanf segmentationfault socketprograming sockets spoonfeeding stdin string strings strtok structures student system testing turbo-c turboc unix user variable win32 windows _getdelim






