#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/time.h>
#include <errno.h>
typedef struct data {
char *str;
long time;
int symbal;
} DATA;
int64_t getCurrentTime()
{
struct timeval tv;
gettimeofday(&tv,NULL);
return tv.tv_sec * 1000 + tv.tv_usec / 1000;
}
int write_log(char *c){
FILE *fp;
ong curTime = getCurrentTime();
int line_count;
* Pt the DATA;
Pt = (the DATA *) the malloc (the sizeof (the DATA));
// the memcpy (Pt-> STR, C, strlen (C)); when using such an approach using arrays
pt-> str = c;
Pt-> Time = curTime;
Pt-> = symbal;
the printf ( "% S \ n-", Pt-> STR);
FP = the fopen ( "the SYSTEM.LOG", "R & lt +");
IF (FP == NULL) {
fprintf (stderr, "File Open the SYSTEM.LOG error% S \ n-!", the strerror (errno));
// doSystem ( "Touch xxxfile.log");
return 0;
}
while((line_count = fgetc(fp)) != EOF)
{
if(line_count == '\n') {
line_count++;
}
if (line_count < 100) {
//fseek(fp, sizeof(*fp), SEEK_END);
fwrite(pt,sizeof(DATA),1,fp);
} else {
//doSystem(" sed -i '0,49d' system.log ");
fwrite(pt,sizeof(DATA),1,fp);
}
free(pt);
fclose(fp);
return 0;
}
int main(int argc, char **argv)
{
char *p = "As food is to the body";
int ret = write_log(p);
printf("%d\n", ret);
return ret;
}