I'm trying to return a struct
from 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'm trying to return the content in the returnDuo
struct but I get the error message: "Expected identifier or '('". If I use void
function its working as expected without returning anything but I cant figure out how to return this struct
.
This is how I setup the structs.
struct vara {
char varuNr[5];
char varuNamn[50];
int lagerSaldo;
};
struct returnera {
int antalVaror;
char filnamn[LISTNUMBER];
};
And how I setup them up in main.
struct vara varuArray[SIZE];
struct returnera returnDuo = {0,"0"};
I gladly take any tips on how to get this to work...