파일 인스턴스 쓰기

4369 단어 structBlogFilenullFP
*      :          :    0- ,-1-      out:        , fmt      fmt:        0- :yyyy-mm-dd hh24:mi:ss, 1- :yyyy-mm-dd, 2- :hh24:mi:ss */ int getTime( char *out, int fmt)                 // {      if (out == NULL)          return -1;          time_t t;      struct tm *tp;      t = time (NULL);          tp = localtime (&t);      if (fmt == 0)          sprintf (out, "%2.2d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d" , tp->tm_year+1900, tp->tm_mon+1, tp->tm_mday, tp->tm_hour, tp->tm_min, tp->tm_sec);      else if (fmt == 1)          sprintf (out, "%2.2d-%2.2d-%2.2d" , tp->tm_year+1900, tp->tm_mon+1, tp->tm_mday);      else if (fmt == 2)          sprintf (out, "%2.2d:%2.2d:%2.2d" , tp->tm_hour, tp->tm_min, tp->tm_sec);      return 0; }     FILE * openFile( const char *fileName, const char *mode)  // {      FILE *fp = fopen (fileName, mode);      return fp; }     /*      :     str      :    0, -1      fp:          str:             bLog:       1- ,0-      :     , str ( :2011-04-12 12:10:20) */ int writeFile( FILE *fp, const char *str, int bLog)          // ,bLog {      assert (fp != NULL && str != NULL);      char curTime[100] = {0};      int ret = -1;      if (bLog) //      {          getTime(curTime, 0);          ret = fprintf (fp, "[%s] %s
"
, curTime, str);      }      else          ret = fprintf (fp, "%s
"
, str);          if (ret >= 0)      {          fflush (fp);          return 0;               //      }      else          return -1; }     int closeFile( FILE *fp) {      return fclose (fp); }

좋은 웹페이지 즐겨찾기