|
-
July 5th, 2006, 12:03 PM
#1
Dynamic struct array malfunction...
I get an assertion error after entering the data in the array. If I use the static array all is fine but I really need a dynamic one...
anyone see any errors?
--------------------------------
struct student {
int brIndeks;
char ime[25];
int bodovi[4];
int ocjena;
};
void unos(student *stud, int n);
int main() {
int n=0;
student *stud = new student[n];
cin>>n;
unos(stud, n);
return 0;
}
void unos(student *stud, int n){
for(int i=0; i<n; i++){
cout<<"Unesite broj indeksa za "<<i+1<<" studenta"<<endl;
cin>>stud[i].brIndeks;
cout<<"unesite broj bodova s 1. testa: "<<endl;
cin>>stud[i].bodovi[0];
cout<<"unesite broj bodova s 2. testa: "<<endl;
cin>>stud[i].bodovi[1];
cout<<"unesite broj bodova s kolokvija: "<<endl;
cin>>stud[i].bodovi[2];
cout<<"unesite broj bodova s zavrsnog ispita: "<<endl;
cin>>stud[i].bodovi[3];
cout<<"Unesite ime i prezime za "<<i+1<<" studenta"<<endl;
cin.getline(stud[i].ime, 25);
if(cin.gcount()==1){
cin.getline(stud[i].ime, 25);
}
}
}
Last edited by Toltec7; July 5th, 2006 at 12:06 PM.
-
July 5th, 2006, 12:08 PM
#2
Re: Dynamic struct array malfunction...
For one, you allocate the array with n elements BEFORE you
input the value of n.
-
July 5th, 2006, 12:15 PM
#3
Re: Dynamic struct array malfunction...
 Originally Posted by Philip Nicoletti
For one, you allocate the array with n elements BEFORE you
input the value of n.
**** that was it....
can`t believe I missed it....
thanx dude
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|