473,326 Members | 2,337 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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
Expand|Select|Wrap|Line Numbers
  1.   #include<stdio.h>
  2.   void main()
  3.   {
  4.    void fun(int, ...);
  5.    fun(1,2);
  6.   }
  7.  
  8.   void fun(int a,int b)
  9.   {
  10.    printf("%d%d",a,b);
  11.   }
  12.  
  13. but if i write the progran as given below it's not working it's giving error.
  14. #include<stdio.h>
  15. void main()
  16. {
  17.  void fun(int, ...);
  18.  fun(1,2);
  19.  fun(1,2,3);
  20. }
  21.  
  22. void fun(int a,int b)
  23. {
  24.  printf("%d%d",a,b);
  25. }
  26.  
  27. void fun(int a,int b,int c)
  28. {
  29.  printf("%d%d%d",a,b,c);
  30. }
  31.  
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
Mar 23 '08 #1
2 2261
Ganon11
3,652 Expert 2GB
Here is what you need to create printf-like functions.
Mar 23 '08 #2
Thnks for the link which is given by you. After following that link my doubts were cleared.
Mar 24 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Andrew V. Romero | last post by:
I have been working on a function which makes it easier for me to pull variables from the URL. So far I have: <script language="JavaScript"> var variablesInUrl; var vArray = new Array(); ...
17
by: ethan | last post by:
Hi All, How to write a macro with variable length of argument? For example, if i need a macro to check return value of printf. #define PRINTF_ESC(x, ...) if(printf(x, ...) == 10) goto end; ...
182
by: Jim Hubbard | last post by:
http://www.eweek.com/article2/0,1759,1774642,00.asp
5
by: shaanxxx | last post by:
i have statements printf("%f",(double)1); /* works fine although i have sent %f for double */ printf("%c",(int)64); /* works fine although i have sent %c for int */ Need your comment on...
148
by: onkar | last post by:
Given the following code & variable i . int main(int argc,char **argv){ int i; printf("%d\n",i); return 0; } here i is allocated from bss or stack ?
33
by: Michael B Allen | last post by:
Hello, Early on I decided that all text (what most people call "strings" ) in my code would be unsigned char *. The reasoning is that the elements of these arrays are decidedly not signed. In...
4
by: Vlad | last post by:
I am having problems using the file.create method within a function that is called when looping through an array of filepaths. If I call my function with a hardcoded file path --C:\Temp.txt the...
4
by: sirjohnofthewest | last post by:
If I possessed the power to sway the mind of every user in the world to delete all forms of Internet Explorer I would die a happy man. Hi guys, I frequently visit this site to get answers to my...
11
by: Googy | last post by:
Hi friends!! As we know that the input parameters in a function is fixed when the function is defined but how does printf processes variable number of input arguments ? For example: 1....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.