| 5 | 1/1 | 返回列表 |
| 查看: 1243 | 回復(fù): 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ā)表 | |
|---|---|---|---|---|
|
[考研] 環(huán)境工程297分求調(diào)劑一志愿杭高院 +11 | GENJIOW 2026-03-31 | 12/600 |
|
|---|---|---|---|---|
|
[考研] 298求調(diào)劑 +3 | zzz,,r 2026-04-02 | 6/300 |
|
|
[考研] 一志愿復(fù)旦材料,英一專碩,總分357調(diào)劑 +3 | 1050389037 2026-04-02 | 4/200 |
|
|
[考研] 08工科275分求調(diào)劑 +13 | AaAa7420 2026-03-31 | 13/650 |
|
|
[考研] 一志愿上海海洋大學(xué)083200食品學(xué)碩,求調(diào)劑,接受其他專業(yè) +5 | what張 2026-04-01 | 5/250 |
|
|
[考研] 298求調(diào)劑 +4 | 什么是胖頭魚 2026-03-30 | 6/300 |
|
|
[考研] 一志愿西安交大材料學(xué)碩(英一數(shù)二)347,求調(diào)劑到高分子/材料相關(guān)專業(yè) +7 | zju51 2026-03-31 | 9/450 |
|
|
[碩博家園] 考研調(diào)劑 +5 | 駱駝男人 2026-04-01 | 5/250 |
|
|
[考研] 283求調(diào)劑 +9 | A child 2026-03-28 | 9/450 |
|
|
[論文投稿]
chinese chemical letters英文版投稿求助
120+4
|
Yishengeryi 2026-03-30 | 5/250 |
|
|
[考研] 0710生物學(xué)求調(diào)劑! +6 | 敘述文 2026-03-31 | 6/300 |
|
|
[考研] 352分-085602-一志愿985 +6 | 海納百川Ly 2026-03-29 | 6/300 |
|
|
[考研] 375求調(diào)劑 +7 | 雨夏整夜 2026-03-29 | 7/350 |
|
|
[考研] 考研調(diào)劑求助 +7 | 13287130938 2026-03-31 | 7/350 |
|
|
[考博] 材料專業(yè)申博 +5 | 杜雨婷dyt 2026-03-29 | 5/250 |
|
|
[考研] 287求調(diào)劑 +17 | land xuxu 2026-03-26 | 17/850 |
|
|
[考研] 293分求調(diào)劑,外語為俄語 +5 | 加一一九 2026-03-31 | 5/250 |
|
|
[考研] 085600,材料與化工321分求調(diào)劑 +10 | 大饞小子 2026-03-28 | 10/500 |
|
|
[考研] 298求調(diào)劑 +4 | 種圣賜 2026-03-28 | 4/200 |
|
|
[考研] 復(fù)試調(diào)劑,一志愿南農(nóng)083200食品科學(xué)與工程 +5 | XQTJZ 2026-03-26 | 5/250 |
|