小编use*_*826的帖子

由于释放内存导致的分段错误

我一直在努力解决这个问题,但无济于事.在下面的代码中,我使用了一个char指针(all_seq),但是当我释放它时,在代码的末尾,有时它会出现段错误.我有时说,因为它显然取决于输入文件.使用小输入文件,它很好.有一个大的,它也没关系.对于中等大小的文件,它是段错误的.我只是想不通为什么......

任何想法将不胜感激.谢谢.

/* SeqProb (Sequence Probability) - 2012/03/13 */
/* Given a series of aligned sequences -in one file, one per line- this program calculates the probability of having, in each location, the letter in the first sequence. */

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>

FILE *input_file;
FILE *output_file;

///////////////////////////////
// DECLARATION OF FUNCTIONS: //
///////////////////////////////
int GetSize(FILE *file, int *length, int *lines);
double CalcProb(char *one_seq);

//////////////////////////////////////////////////////////////////
// ************************************************************ //
// **************        START MAIN BLOCK        ************** //
// …
Run Code Online (Sandbox Code Playgroud)

c free pointers segmentation-fault

2
推荐指数
1
解决办法
3199
查看次数

标签 统计

c ×1

free ×1

pointers ×1

segmentation-fault ×1