once again... stupid error....

getting access violation error once again, now the line no. is not showing in the error message.
program in comment.
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<stdio.h>
#include<process.h>
#include<ctype.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
//-----------------------------------------------------------------------------

  class aircraft
  {
     public:

       int long tail_no;
       int flying_hours;
       int no_of_seats;
       char aircraft_name[20],base[20],pilot_name[20],copilot_name[20],pilot_rank[10],copilot_rank[10],armaments[10][20];
       int  qty[10], temp_qty;
       aircraft();
       void enter_aircraftdet();
       void get_aircraftdet();
  };

  aircraft::aircraft()
       {
           strcpy(aircraft_name,"");
           no_of_seats=2;
           flying_hours=0;
           strcpy(base,"");
           strcpy(pilot_name,"");
           strcpy(pilot_rank,"");
           strcpy(copilot_name,"");
           strcpy(copilot_rank,"");
           strcpy(armaments[10],"");
       }

  void aircraft::enter_aircraftdet()
       {
           int i=0;
           cout<<"\n Enter Aircraft Name : ";                   gets(aircraft_name);
           cout<<"\n Enter Tail No. : ";                        cin>>tail_no;
           cout<<"\n Enter The Base Name : ";                   gets(base);
           cout<<"\n Enter Flying Hours : ";                    cin>>flying_hours;
           cout<<"\n Enter Number Of Seats (1 or 2) : ";        cin>>no_of_seats;
           cout<<"\n Enter Pilot's Name (Name or Type \"NULL\" If Not Assigned): ";      cin>>pilot_name;
           cout<<"\n Enter Pilot's Rank (Rank or Type \"NULL\" If Pilot Not Assigned): ";       gets(pilot_rank);
           if(no_of_seats==2)
           {
               cout<<"\n Enter Co-Pilot's Name (Name or Type \"NULL\" If Not Assigned): ";   cin>>copilot_name;
               cout<<"\n Enter Co-Pilot's Rank (Rank or Type \"NULL\" If Co-Pilot Not Assigned): "; cin>>copilot_rank;
           }
           for(int arm=0;arm<10;arm+=temp_qty)
           {
               cout<<"\n Enter The Armaments (Maximum 10): ";   gets(armaments[arm]);
               cout<<"\n Enter Quantity Of Entered Weapon ";    cin>>temp_qty;
               qty[i]=temp_qty;
               i++;
           }
		 }
  void aircraft::get_aircraftdet()
       {
           int i=0;
           cout<<"\n Aircraft Name : ";                         puts(aircraft_name);
           cout<<"\n Tail No. : ";                              cout<<tail_no;
           cout<<"\n Base Name : ";                             puts(base);
           cout<<"\n Flying Hours : ";                          cout<<flying_hours;
           cout<<"\n Pilot's Name ( NULL If Not Assigned): ";               cout<<pilot_name;
           cout<<"\n Pilot's Rank ( NULL If Pilot Not Assigned): ";         cout<<pilot_rank;
           cout<<"\n Co-Pilot's Name ( NULL If Not Assigned): ";            cout<<copilot_name;
           cout<<"\n Co-Pilot's Rank ( NULL If Co-Pilot Not Assigned): ";   cout<<copilot_rank;
           cout<<"\n WEAPON \t\t\t\t QUANTITY\n  ";
           for(int arm=0;arm<10;arm+=qty[i])
           {

               cout<<armaments[arm]<<" \t\t\t\t "<<qty[i]<<endl;
               i++;
           }
       }
//-----------------------------------------------------------------------------

  class pilot
  {
     public:

       char pilots_name[20],  pilots_rank[20], pilots_squadron[20], base[20];
       int flying_hours, aircraft_assigned;
       double salary;

       void enter_pilotdet();
       void get_pilotdet();
  };


  void pilot::enter_pilotdet()
       {
           cout<<"\n Enter Pilot Name : ";                      gets(pilots_name);
           cout<<"\n Enter Rank : ";                            gets(pilots_rank);
           cout<<"\n Enter The Base Name : ";                   gets(base);
           cout<<"\n Enter Flying Hours : ";                    cin>>flying_hours;
           cout<<"\n Enter Assigned Aircraft's Tail No. (No. or Type 0 If Not Assigned): ";  cin>>aircraft_assigned;
           cout<<"\n Enter Salary : ";                          cin>>salary;
		 }
  void pilot::get_pilotdet()
       {
           cout<<"\n Pilot Name : ";                      puts(pilots_name);
           cout<<"\n Rank : ";                            puts(pilots_rank);
           cout<<"\n The Base Name : ";                   puts(base);
           cout<<"\n Flying Hours : ";                    cout<<flying_hours;
           cout<<"\n Assigned Aircraft's Tail No. (0 If Not Assigned): ";  cout<<aircraft_assigned;
           cout<<"\n Salary : ";                          cout<<salary;
       }


//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
  void main()
 {   int choice;
     aircraft plane;
     pilot officer;
     again:
     cout<<"\n\t\t\t*** WELCOME TO INDIAN AIR FORCE PAGE ***";
     cout<<"\n Please Enter Your Task";
     cout<<"\n \t \a1). ADMINISTRATOR ";
     cout<<"\n \t 2). SEARCH FOR AN AIRCRAFT";
     cout<<"\n \t 3). SEARCH FOR A PILOT";
     cout<<"\n \t 4). EXIT";
     cout<<"\n Enter Your Choice Here (1,2,3 or 4):";
     cin>>choice; cout<<'\a';
     clrscr;

//******************************************************************************

     if(choice==1)
     {
         int choice1;
         again1:
         cout<<"\n Select Your Task";
         cout<<"\n \t1). ADD NEW AIRCRAFT DETAILS";
         cout<<"\n \t2). ADD NEW PILOT DETAILS";
         cout<<"\n \t3). EDIT AIRCAFT DETAILS ";
         cout<<"\n \t4). EDIT PILOT DETAILS";
         cout<<"\n \t5). PROMOTE A PILOT";
         cout<<"\n \t6). ASSIGN PILOTS TO AIRCRAFT";
         cout<<"\n \t7). EXIT";
         cout<<"\n Enter Your Choice Here (1,2,3,4,5,6,7 or 8):";
         cin>>choice1;

     if(choice1==1)
     {
           plane.enter_aircraftdet();
           ofstream aircraftfile;
           aircraftfile.open("aircraftfile.dat",ios::out||ios::binary);
           aircraftfile.write((char*)&plane,sizeof(plane));
           aircraftfile.close();
     }

     if(choice1==2)
     {                               
           officer.enter_pilotdet();
           ofstream pilotfile;
           pilotfile.open("pilotfile.dat",ios::out||ios::binary);
           pilotfile.write((char*) &officer,sizeof(officer));
           pilotfile.close();
     }

     if(choice1==3)
     {
           int q=-1;
           fstream aircraftfile;
           aircraftfile.open("aircraftfile.dat",ios::app||ios::in||ios::binary);
           int tno;
           cout<<"\n Enter The Aircraft's Tail Number :";        cin>>tno;
           while(!aircraftfile.eof())
           {
                aircraftfile.read((char*) &plane,sizeof(plane));
                if(tno==plane.tail_no)
                {
                  q++;
                  break;
                }
           };
           if(q==-1)
           {
                cout<<"\n Sorry, Aircraft Not Found.";
                goto again1;
           }
              else
           {
                cout<<"\n Aircraft Found!!";
                cout<<"\n Enter The Following Details :";
                cout<<"\n Enter The Base Name : ";                   gets(plane.base);
           		 cout<<"\n Enter Flying Hours : ";                    cin>>plane.flying_hours;
                int i=0, temp_qty;
        		    for(int arm=0;arm<10;arm+=temp_qty)
        		    {
            		   cout<<"\n Enter The Armaments (Maximum 10): ";   cin>>plane.armaments[arm];
               		cout<<"\n Enter Quantity Of Entered Weapon ";    cin>>temp_qty;
               		plane.qty[i]=temp_qty;
               		i++;
           		 }
     	          aircraftfile.write((char*) &plane,sizeof(plane));
     	     }
    		       aircraftfile.close();
     }

     if(choice1==4)
     {

     }

     if(choice1==5)
     {

     }
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
     if(choice1==6)
     {
          int q=-1;
           fstream aircraftfile;
           aircraftfile.open("aircraftfile.dat",ios::app||ios::in||ios::binary);
           int tno;
           cout<<"\n Enter The Aircraft's Tail Number To Be Assigned Pilot(s) :";        cin>>tno;
           while(!aircraftfile.eof())
           {
                aircraftfile.read((char*) &plane,sizeof(plane));
                if(tno==plane.tail_no)
                {
                  q++;
                  break;
                }
           };
           if(q==-1)
           {
                cout<<"\n Sorry, Aircraft Not Found.";
                goto again1;
           }
              else
           {
                cout<<"\n Aircraft Found!";
                cout<<"\n Enter The Name Of The Pilot :";
                cout<<"\n Enter Rank Of The Pilot :";
                if(plane.no_of_seats==2)
                {
                     cout<<"\n Enter The Name Of The Co-Pilot :";
                     cout<<"\n Enter Rank Of The Co-Pilot :";
                }
     	          aircraftfile.write((char*) &plane,sizeof(plane));
     	     }
    		       aircraftfile.close();
     }
     if(choice1==7)
     {
          cout<<'\a';
          cout<<"\n \t**GOOD BYE**";
          exit(1);
     }

     if(choice1>7)
     {
          cout<<"\n \t INCORRECT CHOICE!!! PLEASE TRY AGAIN!!!\n\n";
          goto again1;
     }

     }

//******************************************************************************

     if(choice==2)
     {
          int q=-1;
           fstream aircraftfile;
           aircraftfile.open("aircraftfile.dat",ios::app||ios::in||ios::binary);
           int tno;
           cout<<"\n Enter The Aircraft's Tail Number :";        cin>>tno;
           while(!aircraftfile.eof())
           {
                aircraftfile.read((char*) &plane,sizeof(plane));
                if(tno==plane.tail_no)
                {
                  q++;
                  break;
                }
           };
           if(q==-1)
           {
                cout<<"\n Sorry, Aircraft Not Found.";
                goto again1;
           }
              else
           {
                cout<<"\n Aircraft Found!!";
                plane.get_aircraftdet();
     	     }
    		       aircraftfile.close();
     }

//******************************************************************************

     if(choice==3)
     {
           int q=-1;
           fstream aircraftfile;
           fstream pilotfile;
           aircraftfile.open("aircraftfile.dat",ios::app||ios::in||ios::binary);
           pilotfile.open("pilotfile.dat",ios::app||ios::in||ios::binary);
           int subcat;
           char name[20];
           cout<<"\n \tDO YOU WANT TO ASSIGN ";
           cout<<"\n \t\t1). PILOT";
           cout<<"\n \t\t2). CO-PILOT";
           cin>>subcat;
           cout<<"\n Enter The Name Of The Pilot To Be Assigned Aircraft :";        gets(name);
           while(!pilotfile.eof())
           {
                pilotfile.read((char*) &officer,sizeof(officer));
                if(strcmp(officer.pilots_name,name)==0)
                {
                  q++;
                  break;
                }
           };

           if(q==-1)
           {
               cout<<"\n Pilot Not Found";
           }
                else
           {

              cout<<"\n Pilot Found!";

           if(plane.tail_no==0)
           {
                 cout<<"\n Enter Aircraft's Tail Number";                       cin>>officer.aircraft_assigned;
           }

           pilotfile.write((char*) &officer,sizeof(officer));

           while(!aircraftfile.eof())
           {
                 aircraftfile.read((char*) &officer,sizeof(officer));
                 if(officer.aircraft_assigned==plane.tail_no)
                 {
                       if(subcat==1)
                       {
                            strcpy(plane.pilot_name,officer.pilots_name);
                       }
                       if(subcat==2)
                       {
                            strcpy(plane.copilot_name,officer.pilots_name);
                       }
                       aircraftfile.write((char*) &officer,sizeof(officer));
                 }
           };
           }
           aircraftfile.close();
           pilotfile.close();
     }

//******************************************************************************

     if(choice==4)
     {
           int q=-1;
           fstream aircraftfile;
           fstream pilotfile;
           aircraftfile.open("aircraftfile.dat",ios::app||ios::in||ios::binary);
           pilotfile.open("pilotfile.dat",ios::app||ios::in||ios::binary);
           char pname[20];
           cout<<"\n Please Enter The Pilot's Name To Be Promoted";                gets(pname);
           while(!pilotfile.eof())
           {
                pilotfile.read((char*) &officer,sizeof(officer));
                if(strcmp(officer.pilots_name,pname)==0)
                {
                  q++;
                  break;
                }
           };
           cout<<"\n Pilot Found!";

     }

//******************************************************************************

     if(choice==6)
     {
           cout<<'\a';
           cout<<"\n \t**GOOD BYE**";
           exit(1);
     }

//******************************************************************************

     if(choice>6)
     {
          cout<<"\n \t INCORRECT CHOICE!!! PLEASE TRY AGAIN!!!\n\n";
          goto again;
     }

//******************************************************************************

     cout<<"\n DO YOU WANT TO DO ANOTHER TASK??";
     cout<<"\n \t 1). GO TO MAIN MENU";
     cout<<"\n \t 2). EXIT";
     cout<<"\n Enter Your Choice Here (1 or 2):";
     cin>>choice;

     if(choice==1)
     {
         goto again;
     }

     if(choice==2)
     {
        cout<<'\a';
        cout<<"\n \t**GOOD BYE**";
        exit(1);
     }

//******************************************************************************

     getch();
 }
THANX IN ADVANCE.
Have you tried using a debugger?
1
2
3
4
5
6
7
8
9
10
11
12
       aircraft::aircraft()
       {
           strcpy(aircraft_name,"");
           no_of_seats=2;
           flying_hours=0;
           strcpy(base,"");
           strcpy(pilot_name,"");
           strcpy(pilot_rank,"");
           strcpy(copilot_name,"");
           strcpy(copilot_rank,"");
           strcpy(armaments[10],"");
       }


armaments is declared like so: char armaments[10][20];

Valid indices for an array are 0 to size-1 where size is the number of elements in the array. Therefore, valid indices for the first dimenions of armaments are 0 to 9. You are accessing outside the bounds of armaments.

#include<iostream.h> hasn't been the correct way of including a C++ header since 1998. You might want to consider upgrading your compiler.

Is there a reason you're mixing C input functions with C++ input streams? Is there a reason you're not using std::string?

See also: http://www.stroustrup.com/bs_faq2.html#void-main
Have you tried using a debugger?

yes, thanks i got the reason for error. i didn't paid attention that i have a debugger.

@cire we're taught like that only in our school, so we have get ourselves used to it. i can do nothing. thanks for your advice.
@cire we're taught like that only in our school, so we have get ourselves used to it.

Then you might consider transferring to a school that's not 15 years behind the times. ;)
Then you might consider transferring to a school that's not 15 years behind the times. ;)

now i'm in my final years, rest of the language i'll better learn myselves :)
what we are taught is nothing.. XD
.

Topic archived. No new replies allowed.