#### Archived

This topic is now archived and is closed to further replies.

# function parameters

## Recommended Posts

Hello! To start with, Im playing with new things when it comes to functions (such as function pointers etc) and I would like to know how to get the parameters passed to a function when I do this: void Test(int x, ...) { } I call my test function with: Test(10, 20, 30, "hi"); But I only know that x is 10. How do I access the other variables? What is the name used for "..."? Sorry for posting this, I would have searched... but I dont know what to search for Thanks

##### Share on other sites
This is an example from an open source chess program that I have read in the past that uses it. Search for the va_ functions on the net, or look them up in a reference book. You need to include stdarg.h I believe. This function below basically is just a printf() wrapper. In the program, it needed fflush() to be called after each outputs, so the author chose to do it like this.

  void VSendToWinboard(const char * szFmt, ...){	char	aszBuf[1024];	va_list	lpArgPtr;	va_start(lpArgPtr, szFmt);	vsprintf(aszBuf, szFmt, lpArgPtr);	printf("%s\n", aszBuf);	fflush(stdout);}[/quote]

##### Share on other sites
Did the author not know about setvbuf(stdout, NULL, _IONBF, 0), or does that not work for some reason? (I haven''t tried it)

##### Share on other sites
yep use the std variable arguments library function

#include <stdarg.h>

+ + +

• ### Forum Statistics

• Total Topics
628368
• Total Posts
2982293

• 10
• 9
• 13
• 24
• 11