I want to know how can I define a function that receives different type of arguments.
For example suppose I want to define a "myprint" function that receives a string to be printed and an integer that shows the background color of the first string.(I have no problems with changing the color in console.)
But if function receives only the first string,it should choose background color as my default,for example black.
I think this question could be answered because "main" function has this capability.It can receive no arguments,or argc and argv.
I am a beginner C programmer.
Edit:
After Frxstrem's answer,I wrote this code that has a void myPrintf(int backgroundColor,int textColor,char * string)
function and I want the same result as Frxstrem's answer for two arg function:
//suppose I have defined colors
#define first(a,...) (a)
#define second(a,b,...) (b)
#define third(a,b,c,...) (c)
#define myprint(...) (myPrintf(first(__VA_ARGS__,BLACK),second(__VA_ARGS__,GRAY),third(__VA_ARGS__)))
void myPrintf(int backgroundColor,int textColor,char * string){
int color=16*backgroundColor+textColor;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),color);
printf("%s",string);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),0x07);
}
int main(){
myprint(,,"hello");//error
}
But I get this error:
error C2059: syntax error : ')'