같은 일을 출력 : 당신은 플래그를 사용할 수
#include <stdio.h>
#include <stdarg.h>
static char buffer[1024];
static char *next = buffer;
static void funcB(){
printf("%s", "My Name is");
printf("%s", "I like ice cream");
}
static void funcA(){
funcB();
// Do stuff iwth buffer here
fprintf(stderr, "stole: %s\n", buffer);
next=buffer; // reset for later.
}
int main() {
funcA();
}
int printf(const char *fmt, ...) {
va_list argp;
va_start(argp, fmt);
const int ret = vsnprintf(next, sizeof buffer-(next-buffer), fmt, argp);
next += ret;
va_end(argp);
return ret;
}
원하는 인스턴스를 처리하는 방법을 나타냅니다 printf가 정상적으로 작동합니다. 예 : fprintf
에 매핑하거나 dlsym()
/유사 전화 번호를 사용하여 실제 통화를 찾습니다.
또한 realloc
을 사용하여 버퍼 크기를보다 효율적으로 관리 할 수 있습니다.
'funcB'가 출력물을 출력하지 않으면 대신'funcA'로 반환하겠습니까? 당신이 제공 한 추상적 인 묘사에서 말하기는 좀 더 구체적입니다. – LihO
* "이것은 C++ 질문입니다."* - C 질문과 비슷합니다. C++이라면 다음과 같이 할 수 있습니다 : [this] (http://stackoverflow.com/a/8076948/168175). – Flexo
내 답변에서 언급 한 것처럼 OS에 특유한 질문처럼 보입니다. –