Passing dynamic array to function
Oct 16, 2013 at 6:12pm UTC
I keep getting an error.
"Linker error: undefined reference to Readanswerkey(char*, int)"
Ultimately I'm going to read answerkey put it in a dynamic variable.
Following the answer key in the same input file will be test answers to compare to the key. I'm mainly trying to get the dynamic array to pass to the function.
Thanks in advance.
The input.txt file simply contains a series of T or F depending on the answer.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
Ex. TTFFTFTFTTFFFTT
#include <string>
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
//Function prototypes
//Function to open data files for use.
void ClosedataFiles(ofstream& outputdata, ifstream& inputdata);
void Readanswerkey(char *answerkey, int questionNumber);
int main()
{
//Variable declaration
ofstream outputdata; //output data variable
ifstream inputdata; // input data variable
string studentid; //student id field
char answerlist;
int questionNumber, testscore, index;
char grade;
char *answerkey;
char *studentanswers;
//Open and test files
outputdata.open("output.txt" );
inputdata.open("input.txt" );
if (!outputdata || !inputdata)
{
cout << "Error opening files" << endl;
system ("pause" );
return 0;
}
// get question number, read data files and ect etc...
cout << "Enter the number of questions: " ;
cin >> questionNumber;
answerkey = new char [questionNumber];// dynamic array for answerkey
studentanswers = new char [questionNumber];// dynamic array for answers
// inputdata >> studentid; // priming data read
Readanswerkey(answerkey, questionNumber);
/* while (inputdata)//end of file loop to process the input data
{
//formats and writes data to output file
// outputdata<<setiosflags(ios::fixed) << setprecision(2)<< setw(1) << radius
// <<setw(9)<<height<<setw(10)<<area<<setw(10)<<volume<<endl;
} */
ClosedataFiles(outputdata, inputdata); // close data files
system("pause" );
}
//Function
//***************************************************************************
void ClosedataFiles(ofstream& outputdata, ifstream& inputdata)
{
outputdata.close();
inputdata.close();
}
//***************************************************************************
void Readanswerkey(char *answerkey, int questionNumber, ofstream& outputdata, ifstream& inputdata)
{
int index;
for (index=0; index < questionNumber; index++)
inputdata >> answerkey[index];
for (index=0; index < questionNumber; index++)
outputdata << answerkey[index];
}
//***************************************************************************
Last edited on Oct 16, 2013 at 6:37pm UTC
Oct 16, 2013 at 6:33pm UTC
Your definition and prototype do not match for Readanswerkey.
Also please use
code tags [code]code goes here[/code]
Last edited on Oct 16, 2013 at 6:35pm UTC
Oct 16, 2013 at 6:37pm UTC
I feel silly posting now. Thanks for the second pair of eyes.
Topic archived. No new replies allowed.