need help!

hello friends,my program first worked correctly but didn't worked when i run it for second time.when i debuged it by dev c++ this message appeared:"an access violation (segmentation fault) raised in your program".what can i do?
Fix the bug in your program that's causing the seg fault.
It probably means that you are going out of bounds of an array somewhere or dereferincing a pointer that hasn't been initialized.

Stick some breakpoints in there and run it in the debugger again. If it crashes, you'll at least know where its crashing.
how can i do that?
this is my code:
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
#include<iostream>
 using namespace std;
 int main()
 {           
		/*************************declaring database structure having special members*/      
		            struct database{
						char pilot_name[50];
						char plane_name[50];
						char offset[50];
						char destination[50];
						char cus_sure[100][50];
						char cus_last[100][50];
						int capacity;
						int fly_number;
						int reserved;
						int year;
						char month[15];
						int day;
						int houre;
						char meridian[2];
						int minute;

					};
/********************************************///declaring fly structure in user_chice numbers

cout<<"how many fly do you want to record?\n";
int rec_num;//declars number of flies user want to record
cin>>rec_num;                       
database fly[rec_num];
/*******************************************/                                          
/*************recieving fly information and save them in fly array database structure**/
        
        for(int i=0;i<rec_num;i++) {
			
			cout<<"enter this fly number:\n";
			cin>>fly[i].fly_number;
			
			cout<<"enter this fly's pilot_name:\n";
			cin>>fly[i].pilot_name;
			
			cout<<"enter this fly's plane_name:\n";
			cin>>fly[i].plane_name;
			
			cout<<"where is fly's offset?:\n";
			cin>>fly[i].offset;
			
			cout<<"where is fly's destination?:\n";
			cin>>fly[i].destination;
			
			cout<<"how many sits are availabe in this fly?:\n";
			cin>>fly[i].capacity;
			
			cout<<"enter fly time in order year,month(string),day,houre,minute:\n";
			cin>>fly[i].year;
			cin>>fly[i].month;
			cin>>fly[i].day;
			cin>>fly[i].houre;
			cout<<"pm or am?\n";
			cin>>fly[i].meridian;
			cin>>fly[i].minute;
			
			cout<<"DO YOU WANT TO RECORD ANOTHER FLY? Y/N?\n";
			char ans;
			cin>>ans;
			if(ans == 'y')
			continue;
			if(ans == 'n')
			break;}
/****************************************************************************************/
//REPORTING RECORDED FLIES PHASE:
	for(int i=0;i<rec_num;i++) {
	cout<<"FLY NUMBER    :       "<<fly[i].fly_number<<endl;
	cout<<"PILOT         :       "<<fly[i].pilot_name<<endl;
	cout<<"PLANE         :       "<<fly[i].plane_name<<endl;
	cout<<"OFFSET        :       "<<fly[i].offset<<endl;
	cout<<"DESTINATION   :       "<<fly[i].destination<<endl;
	cout<<"CAPACITY      :       "<<fly[i].capacity<<endl;
	cout<<"FLY TIME      :       "<<fly[i].year<<"   "<<fly[i].month
	<<"  "<<fly[i].day<<"   "<<fly[i].houre<<":"<<fly[i].minute<<fly[i].meridian<<endl<<endl<<endl;
	
    }
/****************************************************************************************/

	                   //RESERVATION PHASE:
cout<<"DO YOU WANT TO RESERVE ANY TICKETS? Y/N?\n";
char ans1;//customer choice to reserve ticket or not!
cin>>ans1;
                 while(ans1 == 'y') {
						cout<<"WHICH FLY DO YOU WANT TO RESERVE?\n";
			    int cus_choice;//fly number that customer chooses
			    cin>>cus_choice;
			       
			                 if(fly[cus_choice-1].capacity > 0) {
								
								cout<<"YOUR SURE NAME?\n";
								cin>>fly[cus_choice-1].cus_sure[fly[cus_choice-1].reserved];
								
								cout<<"YOUR LAST NAME?\n";
								cin>>fly[cus_choice-1].cus_last[fly[cus_choice-1].reserved];
								
								cout<<"YOUR TICKET HAS BEEN RESERVED\n";
								cout<<"you must go to ticket_office to  receipt your ticket!\n";
								
								fly[cus_choice-1].capacity -= 1;//decreasing fly capacity for 1 after reserving this fly
								fly[cus_choice-1].reserved += 1;//increasing fly reserved number for 1 after reserving this fly
								
								cout<<"DO YOU WANT TO RESERVE ANOTHER FLY? Y/N\n";
								cin>>ans1;
								
								if(ans1 == 'y')
								continue;
								if(ans1 == 'n')
								break;
							}
							
							
							
							if(fly[cus_choice-1].capacity == 0) {
								
								cout<<"SORRY!! THIS FLY IS FULL!\n";
								
								cout<<"DO YOU WANT TO RESERVE ANOTHER FLY? Y/N\n";
								cin>>ans1;
								
								if(ans1 == 'y')
								continue;
								if(ans1 == 'n')
								break;
														
                            }
		     	}
	
/************************************************************************************************/
/*FINAL FLY REPORTING*/

 	for(int i=0;i<rec_num;i++) {
	cout<<"FLY NUMBER    :       "<<fly[i].fly_number<<endl;
	cout<<"PILOT         :       "<<fly[i].pilot_name<<endl;
	cout<<"PLANE         :       "<<fly[i].plane_name<<endl;
	cout<<"OFFSET        :       "<<fly[i].offset<<endl;
	cout<<"DESTINATION   :       "<<fly[i].destination<<endl;
	cout<<"REMAINED CAP  :       "<<fly[i].capacity<<endl;
	cout<<"reserved num  :       "<<fly[i].reserved<<endl;
	cout<<"FLY TIME      :       "<<fly[i].year<<"   "<<fly[i].month
	<<"  "<<fly[i].day<<"   "<<fly[i].houre<<":"<<fly[i].minute<<fly[i].meridian<<endl<<endl<<endl;
    }
/*************************************************************************************************/
//WHO RESERVED WHICH FLY REPORTING PHASE!

  cout<<"people who reseved ticket :\n";
     
                for(int i=0;i<rec_num;i++) {
					
					cout<<"fly number :        "<<fly[i].fly_number<<endl<<endl;
					
					for(int j=0;j<fly[i].reserved;j++) {
						
					cout<<"                    "<<fly[i].cus_sure[j]<<" "<<fly[i].cus_last[j]<<endl<<endl;
						
                    }

                }
/*************************************************************************************************/
return 0;}
thanks alot friends...
1
2
3
int rec_num;//declars number of flies user want to record
cin>>rec_num;                       
database fly[rec_num];


This shouldn't compile. DevC++ is a terrible compiler that you should consider replacing with something that uses the actual C++ standard. In a proper compiler this would give an error because you can't define an array with a non-constant variable. You need to dynamically allocate the memory to make the array variable in length.

Replace those three lines with:
1
2
3
int rec_num;//declars number of flies user want to record
cin>>rec_num;                       
database* fly = new database[rec_num];
DevC++ is a terrible compiler


DevC++ is not a compiler.

GCC has an extension enabled by default that allows VLAs (variable length arrays) in C++ code, however this is not actually legal in C++, so it is recommended to turn off that extension if you want your code to be portable. Consider using a std::vector instead.

If you're using Bloodshed DevC++, it is an outdated IDE which comes with an outdated version of a compiler when you download the two in a package. I would recommend upgrading. If you're using another fork of the DevC++ IDE which is updated regularly, you may disregard the recommendation.
thank you 'cire','stewbond'...
Topic archived. No new replies allowed.