fputs函数无法写东西进文件?
出错内容请看代码中的汉字注释。
#include "precompile.h"
Status macro_collect(const char *sourcefile,
struct macro_argument **macro_argument_head,
struct macro_no_argument **macro_no_argument_head)
{
int flag1 = 1;
int flag2 = 1;
FILE *fpa;
FILE *fpb;
char curLine[MAX_LINE];
ma *malhead; /* ma --> struct macro_argument */
ma *maltail;
mna *mnalhead;/* mna -->struct macro_no_argument */
mna *mnaltail;
malhead = (ma *)malloc(sizeof(ma));
maltail = malhead;
mnalhead = (mna *)malloc(sizeof(mna));
mnaltail = mnalhead;
if (NULL == (fpa=fopen(sourcefile, "r")) ||
NULL == (fpb=fopen("temp2.c", "w")))
{
printf("Cannot open the file!\n");
return ERROR;
}
while (TRUE)
{
if (feof(fpa))
{
break; // end of file
}
if (NULL == fgets(curLine, MAX_LINE-1, fpa))
{
printf("fgets error!\n");
return ERROR;
}
delete_blank(curLine);
if (1 == flag1)
{
flag1 = 0;
maltail->next = (ma *)malloc(sizeof(ma));
maltail = maltail->next;
}
if (1 == flag2)
{
flag2 = 0;
mnaltail->next = (mna *)malloc(sizeof(mna));
mnaltail = mnaltail->next;
}
/*
* If macro_collect_line() return SUCCESS, which means the current * line's macro information has been collected successfully, then * continue to check the next line.
* Else return UNSUCCESS, which means the current line has no macro, * then copy the current line to the "temp2.c" directly and continue * to check the next line. */
if (UNSUCCESS == macro_collect_line(curLine, &maltail, &mnaltail,
&flag1, &flag2))
{
printf("%s\n",curLine);/* 此处字符串curLine可以正常输出内容,但是接下来的fputs函数却没有向文件temp2.c中写入该字符串。*/
if (EOF == fputs(curLine, fpb))
{
printf("Write file error!\n");
return ERROR;
}
}
}
fclose(fpa);
fclose(fpb);
(*macro_argument_head) = malhead->next;
(*macro_no_argument_head) = mnalhead->next;
return OK;
}
相关阅读:
boss让我实现下图的这个功能,能实现添加元素,修改以及删除,我感觉无法下手
coordinatorLayout嵌套recyclerview
使用jquerymobile,如果一个big.html有3个并列的page(A page,B page,C page)
有没有用markdown做成的页面链接
国外地图标记(非洲)
sass 能否内联导入 css?
请教一个prototype的类型问题。tostring()检测
git如何合并两个远端分支?
有人用过Howler.js这个插件吗?遇到ios兼容性问题了,求解答
js中继承之后,子构造器new出来的对象的constructor为什么是父构造器?
前端写JS时候如何实现类似Xcode中playgourd的热替换的功能?
mint-ui vue2.0 调试发现body有个8px的外边距 是什么鬼?官方默认没清么?
在windows上使用nginx拦截node静态资源请求后,怎样从请求中看出来啊?
无限极分类导入问题
select2 如何禁止用户写入tags?
用js如何修改浏览器默认的下载框
css3中的translateZ能够改变元素的层叠顺序吗?
vue做的项目IE下显示空白 调试报错 求解
iOS如何判断竖排方向锁定
Atom beautify 格式化PHP无效果.