I am declaring a structure as this
typedef struct Request
{
deque<int> roomsList ;
}Request;
Then , in some other function I get a segmentation fault in the highlighted line :
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][I](R->roomsList).push_back(roomNum) ;[/I][/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 :
hi 0
hello 0x1849010
bye 0x1849010
hi 1
hello 0x1849010
Segmentation fault
Output of GDB :
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!!