小编dwv*_*009的帖子

内存分配错误 - 在Linux但不是OSX Unix

我正在为统计包编写一些代码,我首先将数据读入指针数组.我初始化指针并使用malloc分配足够的内存; 但是,我有时会在下面的代码末尾的内存分配中出错.

#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include "stats.h"

int main(int argc, char **argv) {
FILE *fp, *outFile, *outBin;    // create a file identifier
size_t n, nbins; // # of data points
double *data; // pointer to hold data
double average, variance, *med; // stat returns
int medianComplete, histComplete, i; // return 1 on success
hist_t *Histogram;

// read in the number of bins from exe arguments
nbins = atoi(argv[1]);
nbins = (size_t)nbins;

// open the binary datafile and …
Run Code Online (Sandbox Code Playgroud)

c linux memory fault

0
推荐指数
1
解决办法
1067
查看次数

标签 统计

c ×1

fault ×1

linux ×1

memory ×1