| 5 | 1/1 | 返回列表 |
| 查看: 1241 | 回復(fù): 4 | ||
| 當(dāng)前只顯示滿足指定條件的回帖,點擊這里查看本話題的所有回帖 | ||
[求助]
麻煩哪位大神幫忙修改一下這個程序,不勝感激! 已有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" ;} |
木蟲 (小有名氣)
至尊木蟲 (正式寫手)
| 最具人氣熱帖推薦 [查看全部] | 作者 | 回/看 | 最后發(fā)表 | |
|---|---|---|---|---|
|
[考研] 一志愿北交大材料工程總分358 +8 | cs0106 2026-04-01 | 9/450 |
|
|---|---|---|---|---|
|
[考研] 一志愿安徽大學(xué)計算機科學(xué)與技術(shù)學(xué)碩,331分求調(diào)劑 +5 | 蔣昌鵬qtj 2026-04-01 | 5/250 |
|
|
[考研] 805600專碩材料與化工348分求調(diào)劑 +6 | 上學(xué)啦! 2026-04-01 | 6/300 |
|
|
[考研] 291求調(diào)劑 +20 | Y-cap 2026-03-29 | 25/1250 |
|
|
[考研] 安全工程 285 求調(diào)劑 +3 | Xinyu56 2026-04-01 | 4/200 |
|
|
[考研] 材料調(diào)劑 +14 | 一樣YWY 2026-04-01 | 14/700 |
|
|
[考研] 085601材料工程找調(diào)劑 +20 | oatmealR 2026-03-29 | 21/1050 |
|
|
[考研] 085600 一志愿9 總分351 求調(diào)劑學(xué)校 +7 | czhcz 2026-03-31 | 9/450 |
|
|
[考研] 材料專碩322分 +9 | 哈哈哈吼吼吼哈 2026-04-01 | 9/450 |
|
|
[考研] 材料與化工調(diào)劑一志愿大連海事085600,349 +9 | 吃的不少 2026-03-30 | 9/450 |
|
|
[考研] 0856調(diào)劑 +7 | 曲聽筠 2026-03-30 | 7/350 |
|
|
[考研] 311(085601)求調(diào)劑 +12 | liziyeyeye 2026-03-28 | 13/650 |
|
|
[考研] 070300化學(xué)專業(yè)279調(diào)劑 +10 | 哈哈哈^_^ 2026-03-31 | 10/500 |
|
|
[考研] 一志愿中海洋材料357 +4 | 麥恩莉. 2026-03-30 | 4/200 |
|
|
[考研] 313求調(diào)劑 +6 | 賣個關(guān)子吧 2026-03-31 | 6/300 |
|
|
[考研] 083000學(xué)碩274求調(diào)劑 +12 | Li李魚 2026-03-26 | 12/600 |
|
|
[考研] 食品工程專碩一志愿中海洋309求調(diào)劑 +5 | 小張zxy張 2026-03-26 | 10/500 |
|
|
[考研] 0703化學(xué)321分求調(diào)劑 +10 | 三dd. 2026-03-30 | 11/550 |
|
|
[考研] 283求調(diào)劑 +3 | A child 2026-03-28 | 3/150 |
|
|
[考研] 調(diào)劑求收留 +7 | 果然有我 2026-03-26 | 7/350 |
|