标签:
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <time.h>
#include <string.h>
int main()
{
char fUrl[] = "c:/document/1.txt";
FILE * fp;
char * tmp;
long len;
int a_len;
time_t tt;
char *a = (char *)malloc(100);
tt = time(NULL);
strcpy(a, asctime(localtime(&tt)));
a_len = strlen(a);
tmp = (char *)malloc(a_len);
strcpy(tmp, a);
fp = fopen(fUrl, "r");
if (fp == NULL)
{
fp = fopen(fUrl, "wb+");
}
fclose(fp);
fp = fopen(fUrl, "rb+");
fseek(fp, 0, SEEK_END);
len = ftell(fp);
rewind(fp);
tmp = (char *)realloc(tmp,len+a_len);
fread(&tmp[a_len], 1, len, fp);
tmp[a_len + len] = 0;
rewind(fp);
fwrite(tmp, 1, a_len+len, fp);
printf("%s\n", tmp);
fclose(fp);
return 0;
}
标签:
原文地址:http://www.cnblogs.com/zhanghaha/p/4488950.html