- 论坛徽章:
- 0
|
这是我的函数:
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()读不出文件的内容;
请指教:
|
|