I am trying to return structfrom a function. It looks like this.
struct read(struct returnera returnDuo, struct vara varuArray[]) {
char varunr[LISTNUMBER], varunamn[LISTNUMBER];
FILE *varuLista;
varuLista = fopen(returnDuo.filnamn, "r");
if(varuLista!=NULL) {
while(fscanf(varuLista,"%s\t%s\t%d\n",varunr, varunamn,
&varuArray[returnDuo.antalVaror].lagerSaldo) == 3){
strncpy(varuArray[returnDuo.antalVaror].varuNr,varunr,5);
strncpy(varuArray[returnDuo.antalVaror].varuNamn,varunamn,30);
returnDuo.antalVaror++;
}
printf("Filen är laddad..\n");
kommaVidare();
}
else {
printf("Filen hittades inte, skapar en tom fil"); kommaVidare();
}
fclose(varuLista);
return returnDuo;
}
I try to return the contents to a structure returnDuo, but I get an error: “Expected identifier or“ (“”. If I use a function void, it works as expected without returning anything, but I can’t figure out how to return this one struct.
This is how I set up the structures.
struct vara {
char varuNr[5];
char varuNamn[50];
int lagerSaldo;
};
struct returnera {
int antalVaror;
char filnamn[LISTNUMBER];
};
And how do I configure them mostly.
struct vara varuArray[SIZE];
struct returnera returnDuo = {0,"0"};
I am happy to accept any advice on how to make this work ...
source
share