Segmentation fault in C++ code using deque STL in push_back function

I am declaring a structure as this

1
2
3
4
typedef struct Request
{
	deque<int> roomsList ;
}Request;

Then , in some other function I get a segmentation fault in the highlighted line :
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
int initRoomsList(Request *R)
{
	int roomSatisfying ;
	char roomName[20] ;
	int roomNum, capacity,wb,proj, lcd, sound, aud, vid , ac ;
	int count = 0;
	FILE *fp ;
	fp = fopen("rooms.txt","r") ;
	while(fscanf(fp,"%d %d %d %d %d %d %d %d %d %s", \
	&roomNum,&capacity, &wb,&proj,&lcd,&sound,&aud,&vid,&ac,roomName) != EOF )
	{
		if(R->capacity > capacity )
			continue ;
		if(R->wb > wb )
			continue ;
		if(R->proj > proj)
			continue ;
		if(R->lcd > lcd )
			continue ;
		if(R->sound > sound )
			continue ;
		if(R->aud > aud)
			continue ;
		if(R->vid > vid )
			continue ;
		if(R->ac > ac)
			continue ;
			
		// If control is here, that means this room fulfils all conditions .
		cout<<"hi "<<roomNum<<endl ;
		cout<<"hello "<<&(R->roomsList)<<endl ; 
		[b](R->roomsList).push_back(roomNum) ;[/b]
		cout<<"bye "<<&(R->roomsList)<<endl ; 
		count++;
	}
	fclose(fp) ;
	if(count==0)
		return 0 ;	
	else
		return 1 ;
	
}

This is what gets printed on the terminal :

1
2
3
4
5
6
hi 0
hello 0x1849010
bye 0x1849010
hi 1
hello 0x1849010
Segmentation fault


Output of GDB :
1
2
3
4
5
6
7
8
9
hi 0
hello 0x60d010
bye 0x60d010
hi 1
hello 0x60d010
 
Program received signal SIGSEGV, Segmentation fault.
0x0000000000406f1c in __gnu_cxx::new_allocator<int>::construct(int*, int const&) ()
(gdb)


Please help me out with this!!
Put a limit when you read into a char *. Or use a std::string instead
1
2
3
4
		if(R->ac > ac)
			continue ;
			
		// If control is here, that means this room fulfils all conditions 
That's confusing. So fulfils the conditions means that all its values don't go over the limits.
¿why don't just concatenate the conditions?
Topic archived. No new replies allowed.