Other test cases for this openFile function?

Posted by igor on Stack Overflow See other posts from Stack Overflow or by igor
Published on 2010-04-04T17:41:46Z Indexed on 2010/04/04 17:53 UTC
Read the original article Hit count: 249

Filed under:
|

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

© Stack Overflow or respective owner

Related posts about c++

Related posts about homework