xin chào mọi người, mình là newbie hiện đang học c theo cuốn headfirst, trong đó có bài:
This is a program that writes timestamped text to the end of a logfile. It would have
been perfectly possible to write this entire program in C, but the programmer has
used a call to system() as a quick way of dealing with the file handling.
See if you can complete the code that creates the operating system command
string that displays the text comment, followed by the timestamp.
còn đây là code của mình
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
char* now(void);
int main() {
char comment[120], cmd[200];
fgets(comment, sizeof(comment), stdin);
sprintf(cmd, "echo %s %s >> reports.log", comment, now());
system(cmd);
return 0;
}
char* now(void) {
time_t t;
time(&t);
return asctime(localtime(&t));
}
vấn đề ở đây là thay vì in vào reports.log, hàm system lại in lên màn hình. Liệu có ai có thể giúp mình không.
P/s : trong sách có nới muốn học chương này mà dùng win thì cần cài cywin, mình cúng đã làm rồi

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?