I have seperate functions for reading from a text file (depending on whether its an int, float or double). I would like just one function with an additional argument (without using a subsequent IF statement). Does anyone have ideas?
Below is the form of my current functions.
float * read_column_f (char * file, int size_of_col){
...
col = (float*) malloc (height_row * sizeof(float));
... return(col);}
double * read_column_d (char * file, int size_of_col){
...
col = (double*) malloc (height_row * sizeof(double));
... return(col);}
int * read_column_i (char * file, int size_of_col){
...
col = (int*) malloc (height_row * sizeof(int));
... return(col);}
EDIT: I want to implement this in C++, the C-style syntax used is due to memory preference.
ANSI C doesn't support function overloading, which is what you are trying to accomplish. C++ does, however. See the StackOverflow link here: Default values on arguments in C functions and function overloading in C
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With