Dec 11, 2015 at 9:46pm UTC
hello guys,
i need some help with my code
in main i have:
int main(){
.
.
struct{
int id;
string nazov;
int rok;
string zaner;
string povod;
int trvanie;
string herci;
}filmy[17];
naplnStrukturu(filmy[],i,line);
.
.
}
function is:
void naplnStrukturu(struct filmy[],int i,string line){
filmy[i].id=idFilmu(line);
}
error : expected unqualified-id befor '[' token
struct outside of main dousn't help
any ideas?
thanks
Dec 11, 2015 at 11:28pm UTC
If you want your structure to be visible outside of main() you'll need to declare it in the global scope. But be sure you leave the variable declaration inside main(). And don't forget to name that structure.
Also when posting code please use code tags.
Dec 13, 2015 at 9:25am UTC
i did what you said and it still don't work
functin:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
void naplnDatabazu(struct actDatabaza herci[], int pocetRiadkovAct,const char *Vstup){
ifstream vstup(Vstup);
string line;
i=0;
while (getline(vstup, line)&&i<pocetRiadkovAct)
{
herci[i].id = idHerca(line);
herci[i].meno = menoHerca(line);
herci[i].priezvisko = priezviskoHerca(line);
herci[i].narodenie = narodenieHerca(line);
herci[i].miestoNar = miestoNarHerca(line);
i++;
}
}
int idHerca(string line){
string id = line.substr(0, 2);
const char *znak = id.c_str();
int result;
sscanf ( znak, "%d" , &result );
return result;
}
i got this in header file:
void naplnDatabazu(struct actDatabaza herci[], int pocetRiadkovAct,const char *inputFile);
outside main:
like you said:
1 2 3 4 5 6 7
struct actDatabaza{
int id;
string meno;
string priezvisko;
string narodenie;
string miestoNar;
};
in main :
1 2
actDatabaza herci[rowInActors];
naplnDatabazu(herci, rowInActors, nazovActVstup.c_str());
i get errors:
invalid use of incomplete type 'struct actDatabaza'
forward declaration of 'struct actDatabaza'
Last edited on Dec 13, 2015 at 12:20pm UTC
Dec 13, 2015 at 2:25pm UTC
actually what is your program?i headache reading your program ==
Dec 13, 2015 at 7:36pm UTC
i need read data from imput file and put them in the struct. i did it in main but i decide that it will be nicer to do it in function and there is the problem... but no more i already did it and it works fine.
sorry for my english i'm just begginer.