Hello,
I am trying to write a function such as:
printValues(int nInts, int nFloats) ;
nInts describes the variable number of int values
passed, and nFloats describes the variable number of float
values passed.
Normally I would think of doing something like:
printValues(int num1, int num2, float num3....) ;
But nInts and nFloats needs to describe number of variables so printValues can be called with something like this in main:
printValues(4, 3, 3.3, 56.6) ;
I tried using enums, and unions but am unsure on how to implement them. Here is the code I've been messing with.
Any suggestions would be greatly appreciated.
#include <stdio.h>
union {
int x;
float y;
char *z;
} U ;
typedef enum {
INT,
FLOAT,
STRING
} Type ;
//void printValues(int nInts, int nFloats) ;
void printValues(int numI1, int numI2, float numF1, float numF2) ;
int main () {
//printValues(4, 3, 55, 66, 77, 88, 34.5, 23.3, 56.6) ;
printValues(4, 3, 3.3, 56.6) ;
}
//test to see it print correctly
void printValues(int numI1, int numI2, float numF1, float numF2) {
printf("1: %d 2: %d 3: %f 4: %f \n", numI1, numI2, numF1, numF2) ;
}
/*void printValues(int nInts, int nFloats) {
Type numInts = INT ;
Type numFloats = FLOAT ;
}*/