sprintf Wrapping, a tough one

This is a discussion on sprintf Wrapping, a tough one within the C++ Programming forums, part of the General Programming Boards category; Heres one ive been scouring the internet for and no one has ever come up with a workable solution. Here ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    5

    sprintf Wrapping, a tough one

    Heres one ive been scouring the internet for and no one has ever come up with a workable solution. Here is the issue.

    I need to write a wrapper for sprintf. In essence I have a function which takes a char string, and an unknown number of arguments. I do some proccessing to the char string and then need to pass the char string as well as the unknown number of arguments off to sprintf for further proccessing and then return the finished product. No one has been able to figure out how to pass on, whole sale, the unknown number of arguments to a function which takes the same. A few people have mentioned possibly using inline assembly to manualy construct the call stack to sprintf, but have never offered any code to the affect and inline assembly such as that is a little bit beyond my abilitys.

    Just incase it makes a differnce. Im coding in Win32 Visual C++ 2005 using ANSI functions. I desperatly hope someone can give me at least a clue in the right direction here.

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Last edited by Dave_Sinkula; 02-03-2006 at 09:33 AM.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Jan 2006
    Posts
    5
    /me Stares at Dave_Sinkula blankly for a minute

    Your kidding... Ive posted on three other boards and asked 4 other fellow coders and no one knew about something this simple?!?!? It seams too good to be true. If it does what it sounds like than THANK YOU VERY MUCH!

    EDIT: I think I see the problem. I never mentioned in my other posts that I was trying to do this with sprintf. I was just asking about forwarding unknown number of args in general, and apperently that just cant be done without inline assembly. But this fixes MY problem anyway. Thanks!
    Last edited by AdmiralKirk; 02-03-2006 at 09:46 AM.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    > A few people have mentioned possibly using inline assembly
    I guess you now know who to cross off your xmas list of "advice" givers.

    > Ive posted on three other boards and asked 4 other fellow coders and no one knew about something this simple?
    The shallowness of many coders "expertese" is something to behold at times.
    I've met at least two "professionals" who didn't know that && and || short-circuited.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sprintf overflows my buffer -- why?
    By Lasston in forum C Programming
    Replies: 26
    Last Post: 06-20-2008, 04:33 PM
  2. sprintf : garbage appended
    By yeller in forum C Programming
    Replies: 9
    Last Post: 12-17-2007, 09:21 AM
  3. sprintf() giving crash to program!!
    By maven in forum C Programming
    Replies: 4
    Last Post: 01-01-2006, 11:26 AM
  4. sprintf and sscanf
    By tommy69 in forum C Programming
    Replies: 10
    Last Post: 04-22-2004, 08:00 PM
  5. Sprintf
    By Trauts in forum C++ Programming
    Replies: 10
    Last Post: 01-15-2003, 12:35 PM

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