[Solved] c++ fgets Segmentation fault (core dumped)


It turns out that fd/fopen was not getting initialized on line 396

The modified code below allowed my program to run:

Here is the code:

393: FILE *fd;
394: char fd_name[512];
395: strcpy(fd_name,npb_list[freq][app][thread].file_name);
396: fd = fopen( fd_name, "r"); // <<- change made to this line
397: cout << "fd_name = " << fd_name << "\n";
398: char cur_step_buff[4096];
399: cout << sizeof(cur_step_buff) << "\n";
400: cout << “location line 400\n”; 
401: fgets (cur_step_buff, sizeof cur_step_buff, fd);
402: int isEnd=0;
403: int last_step=0;

solved c++ fgets Segmentation fault (core dumped)