0
char word[LENGTH+1];

while(fscanf(file,"%s",word)!=EOF)

{

node* new_node=malloc(sizeof(node));

strcpy(new_node->word,word)

}

there is error of strcpy()

error: incompatible pointer types passing
'char *[46]' to parameter of type 'char *'
[-Werror,-Wincompatible-pointer-types]
strcpy(new_node->word,word);
^~~~~~~~~~~~~~
/usr/include/string.h:129:39: note: passing argument to
parameter '__dest' here
extern char *strcpy (char *__restrict __dest, const c...

but if i change the line

strcpy(new_node->word,word);

to

strcpy(*new_node->word,word);
       ^~~~~~~~~~~~~~~~~~~~~

       add a start here

then the error warning disappear.

so i wonder how to get the word pointer in a node. need i append a start before the node pointer?

3
  • In your typedef for the struct node how do you declare the word variable? As a char* or as a char[LENGTH + 1] – ChrisG Jul 5 '15 at 7:31
  • i found i declare char* [LENGTH+1] , then i change to char [LENGTH+1] , and now it compiles rightly. – Sammy Jiang Jul 5 '15 at 8:20
  • Add your answer and select it as correct to help future programmers with the same question. – ChrisG Jul 5 '15 at 8:40
1

the type char *[46] (the type of member word of your node) is an array of 46 strings not a 46-char long string which you want.

strcpy takes 2 strings this is why the compiler complains as the first argument is not a string but an array of strings.

this is also exactly why when you pass *new_node->word it works. because in the latter case, you are accessing the first element in the array of string (which is a string).

1

I found I declare char* [LENGTH+1] , then I change to char [LENGTH+1] , and now it compiles rightly.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .