// simple program to ask for a file name and // then open the file for reading // This version doesn't do error checking // // reads in a valid 9x9 Sudoku puzzle and reports on how many // cells contain each of the digits and how many are empty // // Beth Katz, February 2006 #include #include #include using namespace std; int main( ) { string filename; char ch; int empty = 0; int digits[10] = {0}; cout << "Enter name of file: "; cin >> filename; ifstream theFile(filename.c_str( )); for (int i = 1; i <= 81; i++) { theFile >> ch; if ('.' == ch) { empty++; } else if ('1' <= ch && ch <= '9') { digits[ch - '0']++; } } cout << empty << " empty cells." << endl; for (int i = 1; i <= 9; i++) { if (digits[i] > 0) { cout << digits[i] << " " << char('0'+i) << "s" << endl; } } return 0; }