- Post in | Source
- Post at | 2006/09/27 17:45 | by
myprintf
printf라기보단...
간혹 필요한 것이 인자를 주고 printf, sprintf, fprintf와 같이 찍어내는 방법입니다.
어쩌다 보니 그냥 printf가 되어버렸네요...
좀 더 low level의 자료였다면 더 좋았겠지만 -_-a
당장 필요한 수준의 것만 만들게 되는게 사람인지라 더 low level로 굳이 귀찮게 짤 필요는 못느꼈다는 ㅋㅋㅋ
[pgm@localhost develop]$ ./test#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;
}
현재 시간은 : 20060927/17:42:55 [ERR -1000] test
어떻게 예제를 만들어야 쉬울지 생각하다보니...
결국 그냥 printf입니다. OTL

