fgets读文件读不出来

shaqianqing 2015-01-22 08:31:15

这是我的函数:
int main(void)
{
int i = 0;
char pbuf[256] = "1970-01-01 02:24:51 [Error] WEB ALARM: test_str:[Log utility testing...], test_val:[12, 0xc], abcd[123], bbbl[234]";
FILE* fp = NULL;
int length = 0;
int num = 0;
char buf[256] = {0};
FILE* fp_tmp = NULL;

fp = fopen("/***/size.txt", "wr+"); //这个就是文件路径;
fp_tmp = fp;
while(i < 14)
{
i++;

if(fp == NULL)
{
printf("open file error\r\n");
return;
}

fgets(buf, 300, fp_tmp);
printf("in %s[%d]:buf:%s\n", __FUNCTION__, __LINE__, buf);

fprintf(fp, "%s\r\n", pbuf);
}
fclose(fp);
}

运行结果:
**********:~$ ./for_test
in main[28]:buf:
in main[28]:buf:
in main[28]:buf:
in main[28]:buf:
in main[28]:buf:
in main[28]:buf:
in main[28]:buf:
in main[28]:buf:
in main[28]:buf:
in main[28]:buf:
in main[28]:buf:
in main[28]:buf:
in main[28]:buf:
in main[28]:buf:


这是执行后size.txt的文件内容:
1970-01-01 02:24:51 [Error] WEB ALARM: test_str:[Log utility testing...], test_val:[12, 0xc], abcd[123], bbbl[234]
1970-01-01 02:24:51 [Error] WEB ALARM: test_str:[Log utility testing...], test_val:[12, 0xc], abcd[123], bbbl[234]
1970-01-01 02:24:51 [Error] WEB ALARM: test_str:[Log utility testing...], test_val:[12, 0xc], abcd[123], bbbl[234]
1970-01-01 02:24:51 [Error] WEB ALARM: test_str:[Log utility testing...], test_val:[12, 0xc], abcd[123], bbbl[234]
1970-01-01 02:24:51 [Error] WEB ALARM: test_str:[Log utility testing...], test_val:[12, 0xc], abcd[123], bbbl[234]
1970-01-01 02:24:51 [Error] WEB ALARM: test_str:[Log utility testing...], test_val:[12, 0xc], abcd[123], bbbl[234]
1970-01-01 02:24:51 [Error] WEB ALARM: test_str:[Log utility testing...], test_val:[12, 0xc], abcd[123], bbbl[234]
1970-01-01 02:24:51 [Error] WEB ALARM: test_str:[Log utility testing...], test_val:[12, 0xc], abcd[123], bbbl[234]
1970-01-01 02:24:51 [Error] WEB ALARM: test_str:[Log utility testing...], test_val:[12, 0xc], abcd[123], bbbl[234]
1970-01-01 02:24:51 [Error] WEB ALARM: test_str:[Log utility testing...], test_val:[12, 0xc], abcd[123], bbbl[234]
1970-01-01 02:24:51 [Error] WEB ALARM: test_str:[Log utility testing...], test_val:[12, 0xc], abcd[123], bbbl[234]
1970-01-01 02:24:51 [Error] WEB ALARM: test_str:[Log utility testing...], test_val:[12, 0xc], abcd[123], bbbl[234]
1970-01-01 02:24:51 [Error] WEB ALARM: test_str:[Log utility testing...], test_val:[12, 0xc], abcd[123], bbbl[234]
1970-01-01 02:24:51 [Error] WEB ALARM: test_str:[Log utility testing...], test_val:[12, 0xc], abcd[123], bbbl[234]


很纳闷为什么fgets()读不出文件的内容;
请指教:
...全文
342 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
shaqianqing 2015-01-24
  • 打赏
  • 举报
回复
引用 4 楼 lhylhy 的回复:
[quote=引用 3 楼 u011680603 的回复:] [quote=引用 1 楼 lhylhy 的回复:] 路径不对吧。路径的斜杠都是反的,还连续三个星号。
还有那是Linux下的路径,您关注的点还真奇特[/quote]
引用 2 楼 u011680603 的回复:
[quote=引用 1 楼 lhylhy 的回复:] 路径不对吧。路径的斜杠都是反的,还连续三个星号。
我那只是写的一个模糊路径,那不是重点吧[/quote] 如果文件路径错不会出错吗?[/quote]您还真厉害,佩服佩服
lhy 2015-01-23
  • 打赏
  • 举报
回复
引用 3 楼 u011680603 的回复:
[quote=引用 1 楼 lhylhy 的回复:] 路径不对吧。路径的斜杠都是反的,还连续三个星号。
还有那是Linux下的路径,您关注的点还真奇特[/quote]
引用 2 楼 u011680603 的回复:
[quote=引用 1 楼 lhylhy 的回复:] 路径不对吧。路径的斜杠都是反的,还连续三个星号。
我那只是写的一个模糊路径,那不是重点吧[/quote] 如果文件路径错不会出错吗?
shaqianqing 2015-01-23
  • 打赏
  • 举报
回复
引用 1 楼 lhylhy 的回复:
路径不对吧。路径的斜杠都是反的,还连续三个星号。
还有那是Linux下的路径,您关注的点还真奇特
shaqianqing 2015-01-23
  • 打赏
  • 举报
回复
引用 1 楼 lhylhy 的回复:
路径不对吧。路径的斜杠都是反的,还连续三个星号。
我那只是写的一个模糊路径,那不是重点吧
lhy 2015-01-22
  • 打赏
  • 举报
回复
路径不对吧。路径的斜杠都是反的,还连续三个星号。

13,822

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧