Any help on this would be appreciated. I have been trying to get this heap sort to work by passing my original array from function to function. Whenever I attempt to compile, it tells me that the identifier is not available for each instance of trying to pass the array to another function.
switch (menuSelection) {
case 1:
//open files
int rows = 0;
fstream infile("short.txt", ios::in);
fstream outfile("sortedShort.txt", ios::out);
//get number of rows
infile.seekg(0, ios::end);
rows = infile.tellg() / recordLength;
infile.seekg(0, ios::beg);
//create array and load values into the array
string* recordArray;
recordArray = new string[rows];
for (int i = 0; i < rows; i++) {
getline(infile, recordArray[i]);
}
Thanks for the response. I attempted what you said and I am receiving the same errors.
1>c:\users\aric\documents\visual studio 2010\projects\assignment6\assignment6\pass7_4.cpp(12): error C3861: 'heapify': identifier not found
1>c:\users\aric\documents\visual studio 2010\projects\assignment6\assignment6\pass7_4.cpp(16): error C3861: 'swapVal': identifier not found
1>c:\users\aric\documents\visual studio 2010\projects\assignment6\assignment6\pass7_4.cpp(17): error C3861: 'siftDown': identifier not found
1>c:\users\aric\documents\visual studio 2010\projects\assignment6\assignment6\pass7_4.cpp(26): error C3861: 'siftDown': identifier not found
1>c:\users\aric\documents\visual studio 2010\projects\assignment6\assignment6\pass7_4.cpp(48): error C3861: 'swapVal': identifier not found
That was the problem! Thank you. I had some other errors in the code, but putting my prototypes allowed me to debug the rest of it. Why do some functions work without using prototypes while others (like the ones in this program), require them?
If the compiler has already seen a function definition or declaration (i.e. prototype) before the point at which the function is called, it can understand the function call. So either the declaration is in a header file that you've included, or the function was defined earlier in the file.
If you want a function you've defined to be callable by code in other files (which will probably be the case if you go on to write bigger programs), then you should put the prototypes for those functions in a header file. That way, the other files can just include the header and get those prototypes easily.