I am trying to assign a function assignment to an array, but it does not seem to work when compiled.
The function takeInputsshould return an array. And, as I understand it, I thought it holdInputswas an array. However, it does not seem to compile. What is the mistake here?
struct Inputs
{
char word[10];
};
struct Inputs* takeInputs(struct Inputs *userInputs, int numInputs);
struct Inputs* printInputs(struct Inputs *userInputs);
struct Inputs* takeInputs(struct Inputs *userInputs,int numInputs){
int i;
for (i=0;i<numInputs;i++){
printf("please input the word");
fgets(userInputs[i].word,10,stdin);
}
}
int main(int argc, char const *argv[]){
if (argc!=2){
error("user Input should look like this: ./takes_Input.exe 7");
}
int numInputs = atoi(argv[2]);
struct Inputs allInputs[numInputs];
struct Inputs holdInputs[numInputs];
holdInputs = takeInputs(allInputs,numInputs);
return 0;
}
Error output:
takes_Input.c: In function βmainβ:
takes_Input.c:53:13: error: assignment to expression with array type
holdInputs = takeInputs(allInputs,numInputs);
But I thought I initialized holdInputs as an array? Thank.
source
share