How to create a printf wrapper
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: How to create a printf wrapper

  1. #1
    Join Date
    Jan 2003
    Posts
    104

    How to create a printf wrapper

    I am trying to create a function like:
    void my_printf(char *fmt, ...) which behaves like printf, except that it will also record all the argument passed in to a text file. Can anybody tell me how to do this?

    Thanks.

  2. #2
    Join Date
    Sep 2003
    Location
    Forever Gone... For Now...
    Posts
    1,515
    My initial thought:
    Call my_printf just like you would call printf. Inside of my_printf, use va_list, va_start, va_arg, and va_end to extract the var args. Do what you will with them. Then, call vprintf with the va_list.

    You will know how many arguments were passed by the number of %'s (take %% into account, of course) in char* fmt...
    Thought for the day/week/month/year:
    Windows System Error 4006:
    Replication with a nonconfigured partner is not allowed.

  3. #3
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    Ciao, Andreas

    "Software is like sex, it's better when it's free." - Linus Torvalds


    Article(s): Allocators (STL) Function Objects (STL)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center