loop for partually filling an array and returning the number filled ?

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...

here is the add function:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 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;} 
 long int 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?
Last edited on
Topic archived. No new replies allowed.