Bus error (core dumped) occurs in my program, and the error is locked in the fopen part of the code
void dipget(int icdp, int nti, float *dip, char * tanpath)
{
FILE * dfile;
char *filename;
printf("Choose %d from %s\n",icdp, tanpath);
sprintf(filename, "%s%d.x.dat",tanpath, icdp);
printf("Open file: %s \n", filename);
if((dfile = fopen(filename,"rb"))==NULL) // Bus error
{
printf("\n Open %s File error\n",filename);
exit(EXIT_FAILURE);
}
fread(dip, sizeof(float), nti, dfile);
fclose(dfile);
}
Here, you only need to make one step of modification to solve the problem. The reason is very simple. Before using sprintf, you need to allocate a buffer space to it
char *filename;
Change to
char filename[200];
Read More:
- [Solved] Nginx Certificate Fill Path Error: SSL: error:0200107B:system library:fopen:Unknown error:fopen
- [Solved] Docker Error: Failed to connect to bus: Host is down
- How to Solve Error:‘itoa’ was not declared in this scope
- How to Solve Nginx cross compilation Error
- How to Solve OpenCV CVUI Error: LINK2019
- [Solved] PaddleX ERROR: Unexpected BUS error encountered in DataLoader worker
- How to Solve Git error: out of memory
- How to Solve LeetCode Error: AddressSanitizer:DEADLYSIGNAL
- How to Solve Error: “initializer element is not constant”
- How to Solve m_gshhs_i Error
- [MAC] How to Solve zsh Error: command not found: umi
- MAC: How to Solve VirtualBox cannot open Issues
- M1 Computer: How to Solve pod update
- [app] install and compile libimobililedevice, How to solve the error
- How to Solve Loadrunner Error: Failed to find .cfg file
- How to Solve “parcel segmentation fault” Error in Linux
- How to Solve Huawei ensp40 Error
- How to Solve Error: Cannot find the declaration of element ‘beans’.
- How to Solve Error: Failed to load ApplicationContext
- How to Solve Starrocks Various Error