用Ubuntu20.04.5的vscode运行一个生成数据的代码,运行到图示位置时出错:
ERROR: GDB exited unexpectedly. Debugging will now abort.
The program '/home/zhang/project/MSFinal-master/BDMRS/gen_data' has exited with code -1 (0xf.).
经过断点运行判断是执行完循环后就出错,各位知道是什么原因吗?
这是define.h文件
/***
* This code .h file define size and struct used.
*/
#define FILE_SIZE 500
// only 26*n is support due to invert matrix function
// only 26 and 676 add to git
#define DICT_SIZE 650
#define FILE_PATH "../doc/FILE0001.txt"
#define MATRIX_PATH "../Matrix/Matrix650trans.txt"
#define MATRIXinv_PATH "../Matrix/Matrix650inv.txt"
#define SK_PATH "./SK.txt"
// struct of node
typedef struct tree_node {
int ID; // node ID
double D[2][DICT_SIZE]; // index data
struct tree_node *Pl; // pointer to left node
struct tree_node *Pr; // pointer to right node
int FID; // pointer to file, use file's ID here
} Node;
// max function
double max( double a, double b ){ return (a>b)?a:b; }
这是出现问题的gen_data.c文件
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <time.h>
#include "define.h"
/***
* This code generate the data used in search
*/
int main() {
int i, j;
FILE *fp;
struct stat st = {0};
// initial the random seed
srand( time(NULL) );
// if no dir "doc", creat it
if (stat("./doc", &st) == -1) {
mkdir("./doc", 0700);
}
// for each file
for( i = 0; i < FILE_SIZE; i++ ) {
//initial file name
char filename[] = FILE_PATH;
char *ptr = strstr(filename, "FILE");
sprintf(ptr, "FILE%04d.txt", i+1);
fp = fopen(filename, "w");
// for each keyword in file
for( j = 0; j < DICT_SIZE; j++ ) {
// initial keyword name
char word[] = "aa";
word[0] = 'a' + j / 26;
word[1] = 'a' + j % 26;
// generate keyword size, half set to 0
int a = rand()%(DICT_SIZE*2) - DICT_SIZE;
if( a < 0 ) a = 0;
fprintf(fp, "%s %d\n", word, a);
}
// close file
fclose(fp);
}
return 0;
}