所以我想讀取鐺是一個很大的嚴格的標準執行力度,但是這一次我百思不得其解......段錯誤,以前不是有當GNU編譯,現在用鏘
void readInputFile(const string inputFileName, Geometry &planeGeom, FlightConditions &FC, AircraftChar & aeroChar,
vector<string> &runFileResults, int &vorlaxRun, int &lateralTrue)
{
int inputRuns;
char infile[32], blank, cTest[32], iTest[32];
char aircraftInpFile[80];
char vorlaxCommand[80];
string casTest, inpTest;
double S_ref,span,Cbar,Xbar,Zbar,St_ref,mac_t,Sf_ref,CD_0,Mach,Uinf,rho;
FILE *ofpInput;
strcpy(infile,inputFileName.c_str());
ofpInput = fopen(infile, "r");
assert(ofpInput!=NULL);
fscanf(ofpInput, "%i", &lateralTrue); //0--false only longitudinal analysis, 1--true long and lateral
printf("lateralTrue = %i\n",lateralTrue);
fscanf(ofpInput, "%i", &vorlaxRun); //0--false will input aero data, 1--true will input run files and execute vorlax
printf("Are we running Vorlax? -- %i\n",vorlaxRun);
fscanf(ofpInput, "%i", &inputRuns); //for looping to run all the needed vorlax files
printf("inputRuns = %i\n",inputRuns);
runFileResults.resize(2*inputRuns);
cout << "I made it to the part where I am reading" << vorlaxRun << "\n" << endl;
fscanf(ofpInput, "%s", &blank); //reading in data from input file
fscanf(ofpInput, "%lf %s", &planeGeom.S, &blank);
fscanf(ofpInput, "%lf %s", &planeGeom.b, &blank);
fscanf(ofpInput, "%lf %s", &planeGeom.cBar, &blank);
fscanf(ofpInput, "%lf %s", &planeGeom.xBar, &blank);
fscanf(ofpInput, "%lf %s", &planeGeom.zBar, &blank);
fscanf(ofpInput, "%lf %s", &planeGeom.St, &blank);
fscanf(ofpInput, "%lf %s", &planeGeom.mact, &blank);
fscanf(ofpInput, "%lf %s", &planeGeom.Sf, &blank);
fscanf(ofpInput, "%lf %s", &aeroChar.CD_0, &blank);
fscanf(ofpInput, "%lf %s", &aeroChar.e, &blank);
fscanf(ofpInput, "%lf %s", &FC.mach, &blank);
fscanf(ofpInput, "%lf %s", &FC.uinf, &blank);
fscanf(ofpInput, "%lf %s", &FC.rho, &blank);
fscanf(ofpInput, "%lf %s", &FC.alpha, &blank);
fscanf(ofpInput, "%lf %s", &aeroChar.dEdA, &blank);
cout << "I made it past reading all the planeGeom stuff " << vorlaxRun << "\n" << endl;
//Commented out code section for debugging purposes...
cout << "I made it past reading all the aeroChar stuff" << "\n" << endl;
所以它似乎int vorlaxRun引起的問題很奇怪,所以我將它添加到了我的印刷品中(如上所見)以查看發生了什麼,這是我得到的輸出結果。
Reading inputFileMavericAftCGApproachFlapsDown.dat
lateralTrue = 0
Are we running Vorlax? -- 0
inputRuns = 0
I made it to the part where I am reading0
Segmentation fault: 11
如果我拿出vorlaxRun的第二個實例正在打印,這是我所得到的
Reading inputFileMavericAftCGApproachFlapsDown.dat
lateralTrue = 0
Are we running Vorlax? -- 0
inputRuns = 0
I made it to the part where I am reading0
I made it past reading all the planeGeom stuff
I made it past reading all the aeroChar stuff
Abort trap: 6
我想我會想到中止陷阱6,因爲我不得不註釋掉在一堆線看到發生了什麼的過程。但我不明白爲什麼刪除打印變量到屏幕上的第二個實例導致它神奇的工作......爲什麼,如果我將其添加在最後COUT然後我得到這樣的:
Reading inputFileMavericAftCGApproachFlapsDown.dat
lateralTrue = 0
Are we running Vorlax? -- 0
inputRuns = 0
I made it to the part where I am reading0
I made it past reading all the planeGeom stuff
Segmentation fault: 11
希望我提供了足夠的信息。我完全陌生的叮噹,我從來沒有任何問題,在谷歌搜索後,我仍然失去了這個+ ...
你爲什麼要將C代碼與C++混合? –
編譯所有警告和調試信息(例如'g ++ -Wall -g'或'clang -Wall -g')。我沒有讀你的代碼,但我想你有一些[未定義的行爲](https://en.wikipedia.org/wiki/Undefined_behavior)。使用'gdb'調試器 –
'fscanf(ofpInput,「%s」,&blank);'很可能是[未定義行爲](https://en.wikipedia.org/wiki/Undefined_behavior) –