#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
using namespace std;
// global constant and variables
const string INFILENAME = "sudokutest.txt";
const char PRE_NUM1 = '9';
const char PRE_NUM2 = '8';
const char PRE_NUM3 = '7';
const char HELP_NUM = 'A';
const char POS_NUM1 = '7';
const char POS_NUM2 = '9';
const char POS_NUM3 = '8';
char table1[9][9]; // sudoku table start
char table2[9][9]; // sudoku table finish
// fuction prototypes
void swap(string& buf, char& value);
void loadTable(char table[][9]);
void printTable(char table[][9]);
int main()
{
loadTable(table1); // load tables
cout << " Start " << endl;
printTable(table1); // display table1
cout << endl;
cout << " Finish " << endl;
printTable(table2); // display table2
return 0;
}
/* 1
Function : swap the numbers stated in constants
Precondition : none
Postcondition : table1 and table2 are load using the swaped numbers
Comment : using 'A' to avoide duplication of swap
*/
//swap
void swap(string& buf, char& value)
{
string s = buf;
replace(s.begin(), s.end(), PRE_NUM1, HELP_NUM);
replace(s.begin(), s.end(), PRE_NUM2, POS_NUM2);
replace(s.begin(), s.end(), PRE_NUM3, POS_NUM3);
replace(s.begin(), s.end(), HELP_NUM, POS_NUM1);
value = s.at(0);
}
The program works as intended but I want to try using the swap method. I've tried just putting inside of main but it said something about being overloaded. I can't figure out if I'm missing a prereq or I'm doing something wrong. Any help or comment is appreciated.