有个main.htm的文件,部分代码如下:
<table border="1" width="100%" bordercolor="#003399" bgcolor="#003399">
<tr>
<td width="100%">
<p align="center"><img border="0" src="../res/logo.gif" width="1000" height="78"></p>
</td>
</tr>
</table>
在pc,arm板子上都可以正常显示。
但是将main.htm文件改成main.c后:
fprintf(cgiOut, "<table border=\"1\" width=\"100%\" bordercolor=\"#003399\" bgcolor=\"#003399\">\n");
fprintf(cgiOut, "<tr>\n");
fprintf(cgiOut, "<td style=\"width:100%\">\n");
fprintf(cgiOut, "<p align=\"center\"><img border=\"0\" src=\"../res/logo.gif\" width=\"1000\" height=\"78\"></p>\n");
fprintf(cgiOut, "</td>\n");
fprintf(cgiOut, "</tr>\n");
fprintf(cgiOut, "</table>\n");
网页在pc上正常,但是在arm平台显示出部分源代码:
" bordercolor=\"#003399\" bgcolor=\"#003399\"> ">
将width=\"100%\" 改为width=\"100%%\"后就可以正常显示。
但是我另一个网页也有:fprintf(cgiOut, "<table cellspacing=\"10\" width=\"60%\">\n"); 为什么就可以呢?
我不清楚其中的原因。 请指教!
------解决方案--------------------
printf,sprintf,fprintf 都可以输出固定格式的字符串
例如:
printf("xxx %d women",1);
将会输出: xxx 1 women;
%号是告诉printf,sprintf,fprintf这些函数,接下来的是格式化的内容,请到后面的参数中加载。详见:http://baike.baidu.com/view/410546.htm
所以,\"100%\" 。fprintf会解读为 %" 的格式内容。
要输出真正的%,使用%%转义。