發表文章

目前顯示的是 4月, 2016的文章

fprintf segmentation fault

記錄一下 遇到segmentation fault:11 的case 以為只是某個陣列出錯,結果居然是fprintf找不到檔案引起的 某個程式區塊內容 char fileloc[50]; sprintf(fileloc,"move_trace/Node%d", i+1); n.PrintTrace(fileloc); //略 void Node::PrintTrace(char *filename){    //open the file    outfile = fopen(filename,"w"); } 其中的outfile是Node的成員變數(對C++不熟,不知道是不是跟Java的講法一樣) FILE *outfile; 之後程式執行到下面這行就出現segmentation fault fprintf(outfile,"#period %d, community %d:\n", i, j); 最後debug出來是因為fopen(filename,"w")並沒有成功,好像目錄"move_trace"不先建立就不行