我正在为统计包编写一些代码,我首先将数据读入指针数组.我初始化指针并使用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)