How to assign function output to an array type? In C? -


i try assign assign output of function array, upon compiling, doesn't seem work.

the function takeinputs should return array. and, have it, thought holdinputs array. however, doesn't seem compile. error here?

// holds expression user enters struct inputs   {     char word[10];  };  // declare these:  struct inputs* takeinputs(struct inputs *userinputs, int numinputs);  // must return pointer pointer because returning array  struct inputs* printinputs(struct inputs *userinputs);  struct inputs* takeinputs(struct inputs *userinputs,int numinputs){     /*inputs:         userinputs: array of struct inputs, each of contain string called "word"          numinputs:  integer user      */      int i;     (i=0;i<numinputs;i++){         printf("please input word");                 fgets(userinputs[i].word,10,stdin);     }   }  int main(int argc, char const *argv[]){      //user input should this:  ./takes_input.exe 7     if (argc!=2){         error("user input should this:  ./takes_input.exe 7");     }      // represents number of words user entering      int numinputs = atoi(argv[2]);      struct inputs allinputs[numinputs];     struct inputs holdinputs[numinputs];      holdinputs = takeinputs(allinputs,numinputs);     // printinputs(holdinputs);     return 0; } 

error output:

takes_input.c: in function ‘main’: takes_input.c:53:13: error: assignment expression array type   holdinputs = takeinputs(allinputs,numinputs); 

but thought initialized holdinputs array?? thanks.

the function takeinputs should return array. and, have it, thought holdinputs array. however, doesn't seem compile. error here?

the error in explanation function can't return array, jonathan leffler pointed out in comments.


takes_input.c:53:13: error: assignment expression array type holdinputs = takeinputs(allinputs,numinputs);

but thought initialized holdinputs array??

you did indeed declare holdinputs array, , array. though haven't initialised it, shouldn't problem. error message telling you can't assign array. example,

char foo[4]; foo = "bar";        // error strcpy(foo, "bar"); // fine , dandy, sour candy... 

or take example code, you're assigning array here:

holdinputs = takeinputs(allinputs,numinputs); 

perhaps meant:

memcpy(holdinputs,takeinputs(allinputs,numinputs),numinputs*sizeof *allinputs); 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -