#include<stdio.h>
#include<stdlib.h>
#include<time.h>
char *now()
{
time_t t;
time(&t);
return asctime(localtime(&t));
}
int main(void)
{
char comment[80];
char cmd[120];
fgets(comment,80,stdin);
sprintf(cmd,"echo '%s %s' >>reports.log",comment,now());
system(cmd);
return 0;
}
没有达到预期效果。直接把命令拷贝,在cmd是可以运行的。