가변인자를 받아서 가변인자로 넘기기

yari71의 이미지

사용자 printf 함수를 만들었는데. 가변인자를 넘기는게 잘 안되네요..

void __printf (char *fmt, ...) 
{ 
      va_list ap; 

      va_start(ap, fmt); 

      printf(fmt, ap); 

      va_end(ap); 
} 

int main() 
{ 
      __printf("%d, %d", 1, 2); 

      exit(0); 
} 

위와 비슷한 형태의 구조인데.. __printf 에서 받은 가변인자printf 로 넘길때 잘 안되네요.. 인자 몇개는 찍히기도 하는거 같은데.. 암튼 제대로 된건 아닌듯...
HELP ME ~~~~

익명 사용자의 이미지

man vprintf

이걸 하시려는 건가요?

익명 사용자의 이미지

그리고 자신이 정의하는 함수명을 __로 시작하시는 건 좋은 선택은 아닌거 같습니다?

분명히 로그인했는데 왜 손님으로 글이 써질까요?

yari71의 이미지

printf 는 그저 예를 든것입니다..
실제로 사용할 함수는 mvwprintw 함수입니다..

말씀대로 __printf 는 좋은 함수명은 아니죠.. 시스템 매크로처럼 보이기도 하고.. 실제로 저렇게 사용하지는 않습니다.
글을 쓰자니. 그저 귀차니즘 때문에... ㅎㅎ

익명 사용자의 이미지

yari71 wrote:
사용자 printf 함수를 만들었는데. 가변인자를 넘기는게 잘 안되네요..

void __printf (char *fmt, ...) 
{ 
      va_list ap; 

      va_start(ap, fmt); 

      printf(fmt, ap); 

      va_end(ap); 
} 

int main() 
{ 
      __printf("%d, %d", 1, 2); 

      exit(0); 
} 

위와 비슷한 형태의 구조인데.. __printf 에서 받은 가변인자printf 로 넘길때 잘 안되네요.. 인자 몇개는 찍히기도 하는거 같은데.. 암튼 제대로 된건 아닌듯...
HELP ME ~~~~

가변인자를 다시 printf로 넘길려면 일일히 인자하나하나찍 지정해야되겠죠.

yeppiguy의 이미지

vsprintf 나 vsnprintf함수로 먼저 버퍼에다가 쓰구...그걸 출력하세요.

va_list 인자는 printf에서 처리하지 못합니다.

man vsnprintf 해서 함수 프로토타입 보세요...^^

Fe.head의 이미지

vprintf가 보이는데요 -_-a

       #include <stdarg.h>

       int vprintf(const char *format, va_list ap);
       int vfprintf(FILE *stream, const char *format, va_list ap);
       int vsprintf(char *str, const char *format, va_list ap);
       int vsnprintf(char *str, size_t size, const char *format, va_list ap);

고작 블로킹 하나, 고작 25점 중에 1점, 고작 부활동
"만약 그 순간이 온다면 그때가 네가 배구에 빠지는 순간이야"

yeppiguy의 이미지

Quote:
vprintf가 보이는데요 -_-a

그렇군요....ㅋㅋ...

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.