tags:

views:

36

answers:

2

I am trying to figure out why my function to open a file is failing this autograder I submit my homework into. What type of input would fail here, I can't think of anything else?

Code:

bool openFile(ifstream& ins)
{

 char fileName[256];
 cout << "Enter board filename: ";
 cin.getline(fileName,256);

 cout <<  endl << fileName << endl;

 ins.open(fileName);
 if(!ins) {
  ins.clear();
  cout<<"Error opening file"<<endl;
  return false;
 }

 return true;

}

Here is output from the 'Autograder' of what my program's output is, and what the correct output is supposed to be (and I do not know what is in the file they use for the input)

Autograder output:

*******************************************
*****                                 *****
*****     Your output is:             *****
*****                                 *****
*******************************************
Testing function openFile
Enter board filename:
test.txt
1
Enter board filename:
not a fileName
Error opening file
0


*******************************************
*****                                 *****
*****       Correct  Output           *****
*****                                 *****
*******************************************
Testing function openFile
Enter board filename:
1
Enter board filename:
Error opening file
0
A: 

Well, you do know what the input is that they use. It appears in your program's output! The first input file name is test.txt, the second is not a fileName.

Anyway, it seems that you're printing the filename after you receive it. But no printed filename appears in the correct output. Just stop printing it might help.

(Does anyone else think that the design of this autograder is stupid? When I was being graded by those things, they wouldn't show our own program's output. At least we'd have to set up an SMTP session to have the test input e-mailed to us...)

Thomas
this probably is it.fwiw, we were given an .exe of what the program should behave like, and their version REPRINTED the filename. ugh.
codefail
I can see how that's confusing...
Thomas
A: 
Testing function openFile
Enter board filename:
test.txt
1
Enter board filename:
not a fileName
Error opening file
0

Yours prints out test.txt That is the only difference I see in the outputs

Earlz