I have an array of structures and user input for thr number of elements that will be added, I think I whould then return that number as I am using it in all other functions but I seem to be doing this wrong...
int add_student()
{ int i,m,no;
system("cls");
fp.open("DB.txt",ios::binary|ios::app|ios::out);
if (! fp)
{cout<< "File could not be opened" << endl;
getchar();
return;}
longint size=sizeof(st[i]);
do{
cout<<"Please enter the number of students in this course. ";
cin>>m;
std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
} while(m<1||m>course_size);
for (i=0;i<m;i++)
{ fp.flush();
cout<<"\nThe data for student No: "<<i+1<<":\n\n";
st[i]=data();
fp.seekg(0,ios_base::end);
cin.sync();
no++;
fp.write((char*)&st[i],size);
cout<<endl<<"You have successfully enrolled new student in the course.\n\n\n";
system("pause") ;
system("cls");
}
n+=no;
fp.close();
return n;
}
and then I have n=add_student() in the main function...
actually I am not quite sure if it is possoble to fill an array only partually and then the rest so if that is not possible what option do I have?