| 5 | 1/1 | 返回列表 |
| 查看: 1240 | 回復: 4 | ||
[求助]
麻煩哪位大神幫忙修改一下這個程序,不勝感激! 已有2人參與
|
|
麻煩哪位大神幫忙看一下下面這個程序,編譯的時候會提示W(wǎng)hile(true)處有錯,應(yīng)該怎么改,請告知一下,不勝感激! // stat.cpp : Defines the entry point for the console application. // #include <stdio.h> #include <stdlib.h> #include <math.h> #include <getopt.h> #include <string.h> // Show a simple usage information. void usage(); int main(int argc, char* argv[]) { char opt; // Options charactors int a=30, b=1, c=7; double r_critical = 3.3943e-2; // Critical radius for judging inner or outer double alpha = 1.0e-6; // Error critical for test double equal char ofname[255] = "out.txt"; // Output file name FILE *fin, *fout; unsigned int i = 0; // Treatment index double time = 0.0L; // Total sampling time double time_bak = 0.0L; // time backup unsigned int steps = 0; // Sampling times double y = 0.0L; // axis y pos double z = 0.0L; // axis z pos double r = 0.0L; // Radius double iq = 0.0L; // Irradiation quantity unsigned int inner = 0; // Inner sampling counter unsigned int outer = 0; // Outer sampling counter while ((opt = getopt(argc, argv, "a:b:c:e :r:h" ) != -1) {switch (opt) { case 'a': a = atoi(optarg); break; case 'b': b = atoi(optarg); break; case 'c': c = atoi(optarg); break; case 'e': alpha = atof(optarg); break; case 'o': strcpy(ofname, optarg); break; case 'r': r_critical = atof(optarg); break; case ':': // Go through case '?': // Go through case 'h': // Go through default: usage(); exit(0); }// switch }// while if (optind != argc-1) { fprintf(stderr, "Need a data file.\n" ;fprintf(stderr, "Use option -h to get some helpful message.\n" ;exit(1); } else // Open input & output files if ((fin = fopen(argv[optind], "r" )==NULL){ printf("data file: %s\n", argv[optind]); printf("Open input file %s failed!\n", argv[optind]); exit(1); } if ((fout = fopen(ofname, "w+" ) == NULL){ printf("Open/Create output file %s failed!\n", ofname); exit(1); } // Output table header fprintf(fout, "\tIndex\t\tTime\t\tSteps\t\tInner\t\tOuter\t\tRate\t\tIrradiation\n" ;fprintf(fout, "\t-------\t\t------\t\t------\t\t------\t\t------\t\t------\t\t------\n" ;// Read a line datas do { // Read a line, but just store useful data fscanf(fin, "%le%*le%*le%le%le%*le%*le%*le%*le%*le%*le%*le", &time, &y, &z); if (feof(fin)) // end of file { fprintf(fout, "\t%d\t\t%le\t%d\t\t%d\t\t%d\t\t%f\t\t%f\n", i, time_bak, steps, inner, outer, ((double)inner)/(inner + outer), iq); printf("\t%d\t\t%le\t%d\t\t%d\t\t%d\t\t%f\t\t%f\n", i, time_bak, steps, inner, outer, ((double)inner)/(inner + outer), iq); break; // out of repeat } if (time < alpha) // time == 0 means a new treatment { // Store treatment data if (i > 0) { fprintf(fout, "\t%d\t\t%le\t%d\t\t%d\t\t%d\t\t%f\t\t%f\n", i, time_bak, steps, inner, outer, ((double)inner)/(inner + outer), iq); printf("\t%d\t\t%le\t%d\t\t%d\t\t%d\t\t%f\t\t%f\n", i, time_bak, steps, inner, outer, ((double)inner)/(inner + outer), iq); } // Clear variable relative to treatment steps = 0; inner = 0; outer = 0; iq = 0; time_bak = 0; i++; // increment index } // Increment step counters steps++; // Calculate radius r = sqrt(y*y + z*z); if (r-r_critical > alpha) { outer++; } else { inner++; } // Calculate irradiation quantity //printf("r=%lf\n", r); iq += a*b*pow(10, -1*c*r)*fabs(time-time_bak); time_bak = time; } while (true); // Close files fclose(fin); fclose(fout); //printf("Calculate finished, press ENTER to exit." ;//printf("pow(10, 1) = %f", pow(10, 1)); //getchar(); return 0; } void usage() { printf("[Usage]: stat datafile.\n" ;printf("Options: \n" ;printf("\t-a, -b, -c: set coefficiency relatively.\n" ;printf("\t-o: set output file name.\n" ;printf("\t-e: set alpha used to compare two float number.\n" ;printf("\t-r: set referrence diameter.\n" ;printf("\nDeveloped by Sam <yeahspyme@sina.com>, published under GPL licence.\n" ;} |
木蟲 (小有名氣)
至尊木蟲 (正式寫手)
| 5 | 1/1 | 返回列表 |
| 最具人氣熱帖推薦 [查看全部] | 作者 | 回/看 | 最后發(fā)表 | |
|---|---|---|---|---|
|
[考研] 266分,一志愿電氣工程,本科材料,求材料專業(yè)調(diào)劑 +9 | 哇呼哼呼哼 2026-04-01 | 9/450 |
|
|---|---|---|---|---|
|
[考研] 372分材料與化工(085600)一志愿湖南大學求調(diào)劑 +3 | 藍箋片 2026-04-02 | 3/150 |
|
|
[考研] 319求調(diào)劑 +12 | 太容易1018 2026-04-01 | 12/600 |
|
|
[考研] 324求調(diào)劑 +5 | 想上學求調(diào) 2026-04-01 | 6/300 |
|
|
[考研] 085600,材料與化工321分調(diào)劑 +8 | 大饞小子 2026-03-27 | 10/500 |
|
|
[考研] 求調(diào)劑,一志愿 南京航空航天大學 ,080500材料科學與工程學碩,總分289分 +11 | @taotao 2026-03-29 | 11/550 |
|
|
[考研] 336求調(diào)劑 +5 | kiyy 2026-04-01 | 5/250 |
|
|
[考研] 材料求調(diào)劑 +8 | 呢呢妮妮 2026-04-01 | 8/400 |
|
|
[考研] 282求調(diào)劑 +17 | ycy1201 2026-04-01 | 19/950 |
|
|
[考研] 266分,一志愿電氣工程,本科材料,求材料專業(yè)調(diào)劑 +10 | 哇呼哼呼哼 2026-04-01 | 11/550 |
|
|
[考研] 英一數(shù)二生物信息學287分,本科生物科學,求調(diào)劑 +3 | 碧水xyz 2026-03-29 | 4/200 |
|
|
[考研] 環(huán)境工程調(diào)劑 +9 | hyzzzzzzz. 2026-04-01 | 9/450 |
|
|
[考研] 08工科,295,接受跨專業(yè)調(diào)劑 +6 | lmnlzy 2026-03-31 | 6/300 |
|
|
[考研] 0856材料化工調(diào)劑 總分330 +18 | zhubinhao 2026-03-27 | 18/900 |
|
|
[考研] 311(085601)求調(diào)劑 +12 | liziyeyeye 2026-03-28 | 13/650 |
|
|
[考研] 求化學調(diào)劑 +12 | wulanna 2026-03-28 | 12/600 |
|
|
[考研] 266求調(diào)劑 +3 | 哇呼哼呼哼 2026-03-29 | 3/150 |
|
|
[考研] 抱歉 +4 | 田洪有 2026-03-30 | 4/200 |
|
|
[考研] 317分 一志愿南理工材料工程 本科湖工大 求調(diào)劑 +12 | 芋泥小鈴鐺 2026-03-28 | 12/600 |
|
|
[考研] 材料與化工(0856)304求B區(qū)調(diào)劑 +8 | 邱gl 2026-03-27 | 8/400 |
|