"printf" Style Function

This is a discussion on "printf" Style Function within the C Programming forums, part of the General Programming Boards category; Hi, I'd like to know how printf works, i know how the "%i" and other things work; But how do ...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    70

    "printf" Style Function

    Hi,

    I'd like to know how printf works, i know how the "%i" and other things work; But how do the variables at the end get passed off as arguments, for example:

    printf("%i", variable /* <<-- How would i do this variable argument? */);

    If i wanted to make my own printf, The Prototype would look something like this:

    void printf(char* String);

    I know how to detect %i, %c and things like that, but when i do detect it - Where would i get the variable argument from? Do you know what i mean?

    Where does the variable come from?

    printf("String %i", /*Where does this Come from??*/);

    Since the variable is not in the prototype, there would be a compiler error, so how does it work?

    If you don't understand what i'm asking, just say and i'll try and rephrase it;

    Please help if you can,
    Cya.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >But how do the variables at the end get passed off as arguments
    http://www.rt.com/man/va_arg.3.html

    -Prelude
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    99
    Here is a file that may be of use to you. It is a rewrite of the printf function.
    Attached Files Attached Files

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. dllimport function not allowed
    By steve1_rm in forum C++ Programming
    Replies: 5
    Last Post: 03-11-2008, 04:33 AM
  2. doubt in c parser coding
    By akshara.sinha in forum C Programming
    Replies: 4
    Last Post: 12-23-2007, 01:49 PM
  3. Troubleshooting Input Function
    By SiliconHobo in forum C Programming
    Replies: 14
    Last Post: 12-05-2007, 07:18 AM
  4. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 10:44 AM

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