myprintf

 | Source
2006/09/27 17:45

printf라기보단...
간혹 필요한 것이 인자를 주고 printf, sprintf, fprintf와 같이 찍어내는 방법입니다.
어쩌다 보니 그냥 printf가 되어버렸네요...

좀 더 low level의 자료였다면 더 좋았겠지만 -_-a

당장 필요한 수준의 것만 만들게 되는게 사람인지라 더 low level로 굳이 귀찮게 짤 필요는 못느꼈다는 ㅋㅋㅋ

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#include <stdarg.h>

int myprintf(const char *format, ...) {
   long length;
   va_list ap;

   va_start(ap, format);
       length = vfprintf(stdout, format, ap);
   va_end(ap);

   return length;
}

int main()
{
   time_t t = 0;
   struct tm *now;
   char test[10] = "test";

   time(&t);
   now = localtime(&t);

   myprintf("현재 시간은 : %04d%02d%02d/%02d:%02d:%02d [ERR %d] %s\n",
       now->tm_year + 1900,
       now->tm_mon + 1,
       now->tm_mday,
       now->tm_hour,
       now->tm_min,
       now->tm_sec,
       -1000,
       test);

   return 0;
}

[pgm@localhost develop]$ ./test
현재 시간은 : 20060927/17:42:55 [ERR -1000] test

어떻게 예제를 만들어야 쉬울지 생각하다보니...
결국 그냥 printf입니다. OTL
2006/09/27 17:45 2006/09/27 17:45
Posted by 슈님

트랙백 보낼 주소 : http://www.zeroshoo.com/tt/trackback/28


BLOG main image
내가 인생에 파도가 좀 많아. by 슈님

공지사항

카테고리

전체 (135)
Today (10)
Source (1)
Media (18)
Writings (56)
Attic (2)
Language (11)
Taste (37)

글 보관함

달력

«   2010/03   »
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
Total : 69518
Today : 14 Yesterday : 32