zoukankan      html  css  js  c++  java
  • 日志-demo

    #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;

    DATA *pt;
    pt = (DATA *)malloc(sizeof(DATA)); 
    // memcpy(pt->str, c, strlen(c)); 用数组的时候采用这种写法
    pt->str = c;
    pt->time = curTime;
    pt->symbal = ;
    printf("%s ", pt->str);
    fp=fopen("system.log", "r+");
    if(NULL == fp) {
      fprintf(stderr,"open file system.log error! %s ",strerror(errno));
      //doSystem("touch xxxfile.log");
      return 0;
    }

    while((line_count = fgetc(fp)) != EOF)
    {
      if(line_count == ' ') {
      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 ", ret);
      return ret;
    }

  • 相关阅读:
    按钮水波纹效果
    点击水波纹效果
    实现图片上传预览效果
    css 实现鼠标滑过流光效果
    插件地址参考
    移动前端经验
    移动端开发需要加的meta
    25款css动画库
    oracle 中的next_day函数
    Oracle replace函数
  • 原文地址:https://www.cnblogs.com/Sam-2018/p/log.html
Copyright © 2011-2022 走看看