码迷,mamicode.com
首页 > 其他好文 > 详细

泊松表面重建源码分析

时间:2014-10-03 18:42:04      阅读:430      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   os   ar   for   文件   

在泊松表面重建的源码中有如下一段代码:

 1 #include <stdio.h>
 2 #include <stdarg.h>
 3 #include <string.h>
 4 
 5 //将结果写入的目标文件
 6 char* outputFile = "DumpOutPutTest.txt";
 7 //echoStdout控制是否通过控制台显示出来
 8 int echoStdout = 1;
 9 
10 void DumpOutput(const char* format, ...)
11 {
12     if (outputFile)
13     {
14         FILE* fp = fopen(outputFile, "a");
15         va_list args;
16         va_start(args, format);
17         vfprintf(fp, format, args);
18         fclose(fp);
19         va_end(args);
20     }
21     if (echoStdout)
22     {
23         va_list args;
24         va_start(args, format);
25         vprintf(format, args);
26         va_end(args);
27     }
28 }
29 void DumpOutput2(char* str, const char* format, ...)
30 {
31     if (outputFile)
32     {
33         FILE* fp = fopen(outputFile, "a");
34         va_list args;
35         va_start(args, format);
36         vfprintf(fp, format, args);
37         fclose(fp);
38         va_end(args);
39     }
40     if (echoStdout)
41     {
42         va_list args;
43         va_start(args, format);
44         vprintf(format, args);
45         va_end(args);
46     }
47     va_list args;
48     va_start(args, format);
49     vsprintf(str, format, args);
50     va_end(args);
51     if (str[strlen(str) - 1] == \n) str[strlen(str) - 1] = 0;
52 }
53 int main()
54 {
55     int i;
56     char **comments;
57     int commentNum = 0;
58 
59     comments = new char*[10];
60 
61     for (i = 0; i< 5; i++) comments[i] = new char[1024];
62 
63     DumpOutput("DumpOutput: %9.1f\n", 12.345);
64     DumpOutput2(comments[commentNum++], "#DumpOutput2: %6.1f (s), %5.1f (MB)\n", 2.344, 3.454);
65     DumpOutput2(comments[commentNum++], "#DumpOutput2: %6.1f (s), %5.1f (MB)\n", 3.344, 4.454);
66     DumpOutput2(comments[commentNum++], "#DumpOutput2: %6.1f (s), %5.1f (MB)\n", 4.344, 5.454);
67     DumpOutput("DumpOutput: %9.1f\n", 23.565);
68 
69 }

 

其实通过这里我们就可以知道 

char* outputFile = "DumpOutPutTest.txt";

 

是控制结果输出文件的。生成的文件和源码文件在同一路径下。如下图所示:

bubuko.com,布布扣


 


int
echoStdout = 1;

 

是控制是否将结果输出到控制台。


if (str[strlen(str) - 1] == \n) str[strlen(str) - 1] = 0;

 

这一句也很明显,只在DumpOutput2中出现了,根据意思就是判断最后一字符是否为换行如果是就用0来代替。但是在此之前已经将结果输入到文件并打印到屏幕了。到底为什么这个么写,再议?!

其实有人想知道代码中具体语句的含义,比如:

va_list args;
va_start(args, format);
vprintf(format, args);
va_end(args);

 其实我也看过,不过我现在觉得对于如此庞大的程序来说知道这部分的含义就可以了,具体什么意思,有兴趣的也可以进一步问问Google大神。

泊松表面重建源码分析

标签:style   blog   http   color   io   os   ar   for   文件   

原文地址:http://www.cnblogs.com/liangliangdetianxia/p/4005050.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!