evapisces
March 26th, 2008, 05:49 PM
Hello. I'm having some trouble with a section of a project I'm working on. The general task of the program is to read in a list of student exam answers from a file along with an answer key, score the answers, and print some reports on the results.
Okay, so I have created the following arrays:
char ansKey[MAXLEN];
char id[MAXCT][5];
char responses[MAXCT][MAXLEN];
int indices[MAXCT];
MAXCT = 40 and MAXLEN = 25
I'm am working on the first report. I have to grade the answers against the answer key. So I'm pretty sure I have to do a string compare where I compare each element of the answer key to the repective element in each student's responses. However, I'm not sure how to do this. Here's the function where I fill the arrays and compare the answer key and student responses:
int fillArrays(char key[], char iden[][5], char answers[][MAXLEN], int index[], int ct)
{
ifstream inFile;
inFile.open("P7Grades.txt");
if (!inFile)
{
cout << "Cannot find input file.\n\n";
system("PAUSE");
exit(1);
}
inFile >> key;
int i = -1;
while (!inFile.eof() )
{
i++;
inFile >> iden[i] >> answers[i];
index[i] = i;
}
for (int j = 0; i < ct; j++)
{
for (int k = 0; k < 20; k++)
{
if (strcmp(key[k], answers[j][k]) != 0)
cout << "*" << answers[j][k] << " ";
}
}
return i;
inFile.close();
}
When I run the code, I get this error message:
invalid conversion from 'char' to 'const char*'
(initializing argument 1 of 'int strcmp(const char*, const char*))
and
invalid conversion from 'char' to 'const char*'
(initializing argument 2 of 'int strcmp(const char*, const char*))
I'm not sure what I'm doing wrong. Any help is greatly appreciated. If you need additional info, please let me know.
I'm fairly new to C++, so if you guys could explain things as simple as possible, I would really appreciate it.
Thanks in advance :)
Okay, so I have created the following arrays:
char ansKey[MAXLEN];
char id[MAXCT][5];
char responses[MAXCT][MAXLEN];
int indices[MAXCT];
MAXCT = 40 and MAXLEN = 25
I'm am working on the first report. I have to grade the answers against the answer key. So I'm pretty sure I have to do a string compare where I compare each element of the answer key to the repective element in each student's responses. However, I'm not sure how to do this. Here's the function where I fill the arrays and compare the answer key and student responses:
int fillArrays(char key[], char iden[][5], char answers[][MAXLEN], int index[], int ct)
{
ifstream inFile;
inFile.open("P7Grades.txt");
if (!inFile)
{
cout << "Cannot find input file.\n\n";
system("PAUSE");
exit(1);
}
inFile >> key;
int i = -1;
while (!inFile.eof() )
{
i++;
inFile >> iden[i] >> answers[i];
index[i] = i;
}
for (int j = 0; i < ct; j++)
{
for (int k = 0; k < 20; k++)
{
if (strcmp(key[k], answers[j][k]) != 0)
cout << "*" << answers[j][k] << " ";
}
}
return i;
inFile.close();
}
When I run the code, I get this error message:
invalid conversion from 'char' to 'const char*'
(initializing argument 1 of 'int strcmp(const char*, const char*))
and
invalid conversion from 'char' to 'const char*'
(initializing argument 2 of 'int strcmp(const char*, const char*))
I'm not sure what I'm doing wrong. Any help is greatly appreciated. If you need additional info, please let me know.
I'm fairly new to C++, so if you guys could explain things as simple as possible, I would really appreciate it.
Thanks in advance :)