Is it possible to pass an argument list between mutliple functions?

This is a discussion on Is it possible to pass an argument list between mutliple functions? within the C Programming forums, part of the General Programming Boards category; I have a program I've been working on and revising for quite some time, and I keep trying to cut ...

  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    161

    Is it possible to pass an argument list between mutliple functions?

    I have a program I've been working on and revising for quite some time, and I keep trying to cut down on repetitive stuff. I'm trying to come up with an easier way to show errors while including variables. I need to show info about the input that caused the error. I don't like having to declare a char array, sprintf, and MessageBox everywhere. I want a 1 line solution like a ShowError function that I basically send printf formatted input to. Problem being, can I turn around and pass the whole argument list to sprintf somehow? I've used the va_list stuff before for other things, but I don't know how I'd go about passing the whole list at once or if it's even possible. I'd probably never be passing more than 4 or 5 vars, so maybe I could make the function go through processing everything separately if I had to. I thought I'd see if anyone here had a better idea though.

    Code:
    ShowError("Address %x is too high. Area specified must be between %x and %x.", Var1, Var2, Var3);
    
    int ShowError(const char* FmtString, ...)
    {
    char tmpText[4096];
    sprintf(tmpText, FmtString, ...);
    MessageBox(NULL, tmpText, "Error", MB_OK);
    }

  2. #2
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    >>Problem being, can I turn around and pass the whole argument list to sprintf somehow?

    Use vsprintf.

    Question 15.12

  3. #3
    Registered User
    Join Date
    Jun 2008
    Posts
    161
    Nice. Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 10:43 AM
  2. deleting a node in linked list
    By BoneXXX in forum C Programming
    Replies: 18
    Last Post: 12-17-2007, 11:30 AM
  3. Reverse function for linked list
    By Brigs76 in forum C++ Programming
    Replies: 1
    Last Post: 10-25-2006, 10:01 AM
  4. Anyone good with linked list.....I am not....
    By chadsxe in forum C++ Programming
    Replies: 11
    Last Post: 11-10-2005, 01:48 PM
  5. How can I traverse a huffman tree
    By carrja99 in forum C++ Programming
    Replies: 3
    Last Post: 04-28-2003, 05:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21