I want to create variable length parameters function in c language like printf()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rameshbabupeddapalli
    New Member
    • Mar 2008
    • 5

    I want to create variable length parameters function in c language like printf()

    Hi,

    I want to create my own variable length parameters function it should work like printf() function.

    When i write the program as given below it's working fine
    [code=c]
    #include<stdio. h>
    void main()
    {
    void fun(int, ...);
    fun(1,2);
    }

    void fun(int a,int b)
    {
    printf("%d%d",a ,b);
    }

    but if i write the progran as given below it's not working it's giving error.
    #include<stdio. h>
    void main()
    {
    void fun(int, ...);
    fun(1,2);
    fun(1,2,3);
    }

    void fun(int a,int b)
    {
    printf("%d%d",a ,b);
    }

    void fun(int a,int b,int c)
    {
    printf("%d%d%d" ,a,b,c);
    }
    [/code]
    The error message is :
    error C2084: function 'void __cdecl fun(int ,... )' already has a body

    My Questions is Why it's giving error?
    We can write many printf functions with different argument lists in a single block, How printf() is working and why my fun() is not working?
    please answer to my questions
    Last edited by sicarie; Mar 23 '08, 12:22 AM. Reason: Code tags, removing phone number - do you really thing that is a good idea?
  • Ganon11
    Recognized Expert Specialist
    • Oct 2006
    • 3651

    #2
    Here is what you need to create printf-like functions.

    Comment

    • rameshbabupeddapalli
      New Member
      • Mar 2008
      • 5

      #3
      Thnks for the link which is given by you. After following that link my doubts were cleared.

      Comment

      Working...