I am using a g++ compiler. The program will read from keyboard input or a given file. It will read in numbers and put them in the array for sorting later.
Here is part of my int main (argc, argv[])
int useFile = 0; // the state of using a given file
double array[numEle};
iftream in;
...
if (usefile)
read_file (in, array, numEle, act_read);
else
read_keyboard (array, numEle, act_read);
-------------------------------------
function prototype
void read_file (ifstream& infile, double hold[], numEle, num_read)
{
for (int i=0; i <numEle, i++)
{infile >> hold[i];
num_read++
}
void read_keyboard (double hold[], numEle, num_read)
{ ...cin >>...
}
--------------------------------------
Questions:
Do I need 2 functions? one for reading files, one for reading keyboard input? I am struggling between ifstream and istream...
Can two different functions in the same file share the same variable name?
If I define numEle in main.h as a constant (to regulate the maximam numbers of array items), can I use it in other source files? Is this a Global varialbe? If Global variable is not allowed, how can I pass the array to do input and output in other source files?
Thank you for your time and helping me through these questions!