473,396 Members | 1,858 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,396 software developers and data experts.

Variadic Functions

Hi all,
Its again me only.... no only i am learning variadic functions topic and as soon as i completed i thought to write a example function . but i got stuck up!....

See i wants to write a variadic function called xstrcpy() in which the minimum number of arguments should be 2 and max is virtually the maximum number the c compiler supports. but i don't want a parameter to specify how many arguments that i am going to pass at the time of function call...

So is there any mechanism in c/c++ to find the number of arguments that is supplied to the called function?

Here is my code for xstrcpy()
Expand|Select|Wrap|Line Numbers
  1. void xxstrcpy(short temp,char *dest,const char *src,...)
  2. {
  3.     va_list strings;
  4.     xstrcpy(dest,src);
  5.     va_start( strings, src) ;
  6.     while ( temp-- )
  7.         {
  8.             xstrcat(dest, va_arg ( strings, char * )) ;
  9.         }
  10.  
  11.     va_end ( strings ) ;
  12. }
  13.  
  14. int main()
  15. {
  16.  
  17.     char sstring[255];
  18.     xxstrcpy(3,sstring,"hello ","welcome "," wih u the best"," bad programmer");
  19.     printf("%s", sstring);
  20.     getch();
  21.     return 0;
  22. }

So i wanna to get rid of the argument1 which specifies how many strings i am going to pass for the function to perform strcat() operation.



So plese help me on this!.......
May 4 '07 #1
2 1764
Ganon11
3,652 Expert 2GB
I think you need that count variable to know how many arguments are passed...sorry!
May 4 '07 #2
AdrianH
1,251 Expert 1GB
So is there any mechanism in c/c++ to find the number of arguments that is supplied to the called function?
Short answer: No.

Long answer: Variadic functions have no mechanism for determining how many arguments are passed. That is why the standard requires that a variadic function has at least one non-variadic parameter.

So i wanna to get rid of the argument1 which specifies how many strings i am going to pass for the function to perform strcat() operation.
If you want to pass a bunch of strings and know how many there are, try passing them as a vector.


Adrian
May 5 '07 #3

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

Similar topics

2
by: Loony | last post by:
Hi, I want to use variadic functions with stl containers as arguments but I am not sure if that is possible and if so how. I'm using gcc 3.3 on Suse 8.2 Hope someone can help me. Thanx...
3
by: Loony | last post by:
Hi, I have a problem with my code. I am using a virtual class in which I define a variadic function. This class is inherited by another one which then implements it. The problem occurs while...
89
by: Sweety | last post by:
hi, Is main function address is 657. its show in all compiler. try it & say why? bye,
5
by: Christopher Benson-Manica | last post by:
Do variadic functions (such as printf()) always scan the format string for format specifiers, even when there are no additional arguments? If it is instead a QoI issue, what would be true for a...
19
by: Ross A. Finlayson | last post by:
Hi, I hope you can help me understand the varargs facility. Say I am programming in ISO C including stdarg.h and I declare a function as so: void log_printf(const char* logfilename, const...
2
by: Florian G. Pflug | last post by:
Hi I faintly remember that I once stumbled upon a way to declare variadic functions (functions that take a variable number of arguments) in plpgsql - but I just searched the docs and can't find...
9
by: CryptiqueGuy | last post by:
Consider the variadic function with the following prototype: int foo(int num,...); Here 'num' specifies the number of arguments, and assume that all the arguments that should be passed to this...
4
by: Boltar | last post by:
Hi Is it possible to nest variadic functions? Eg to do something like this: void mainfunc(char *fmt, ...) { va_list args; va_start(args,fmt);
4
by: Boltar | last post by:
Hi I think I posted a question similar to this on here a while back but I can't find the thread and I need something more general anyway. My problem is I have 2 variadic functions , one of...
8
by: Christof Warlich | last post by:
Hi, is there any way to access individual elements in the body of a variadic macro? I only found __VA_ARGS__, which always expands to the complete list. Thanks for any help, Christof
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.