调用系统函数system(cmd),"echo '%s %s '>>reports.log"显示注释与时间戳出问题,不生成文件
程序源自《嗨翻C语言》P400
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
char * now()
{
time_t t;
time(&t);
return asctime(localtime(&t));
}
int main()
{
char comment[80];
char cmd[120];
fgets(comment,80,stdin);
sprintf(cmd,"echo '%s %s' >> reports.log",comment,now());/*这里有什么问题?*/
system(cmd);
return 0;
}
问题:
1、为何不生成reports.log文件,输入C yuyanbianxie,命令行窗口显示'C yuyanbianxie
采用的工具是mingw编译器,编译未产生错误提醒,time函数也是可以正常使用的,求解