#include <stdlib.h>
int main()
{
FILE *pf = fopen("a.txt", "r")
if(pf == NULL) {
printf("open a.txt file failed!\n")
exit(0)
}
FILE *pf2 = fopen("b.txt", "w")
if(pf2 == NULL) {
printf("open b.txt file failed!\n")
fclose(pf)
exit(0)
}
char ch
while(!feof(pf)) {
ch = fgetc(pf)
putchar(ch)
fputc(ch, pf2)
}
fclose(pf2)
fclose(pf)
return 0
}
1. asctime(local)函数,是将struct tm*类型的参数转换成字符串类型,这样,方便fprintf函数将时间按照字符串输出来2. “w+"是从文件开始写入。所以,每次重写都会覆盖以前的时间。可以使用"a+",在文件后面追加。即,将fp=fopen("time.txt", "w+")改成fp=fopen("time.txt", "a+")
3.有一个网站,可以查找linux的系统api函数
http://linux.die.net/
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)