-
Notifications
You must be signed in to change notification settings - Fork 0
/
utilities.cpp
100 lines (90 loc) · 1.7 KB
/
utilities.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <fstream>
#include <string>
#include <sstream>
#include "utilities.h"
#include "scacchiera.h"
using namespace std;
template <class T>
string NumToString(T num)
{
ostringstream myStream;
myStream << num << flush;
return(myStream.str());
}
string IntToString(int num)
{
ostringstream myStream;
myStream << num << flush;
return(myStream.str());
}
string DoubleToString(double num)
{
ostringstream myStream;
myStream << num << flush;
return(myStream.str());
}
bool checkfile(const char* file)
{
bool temp;
ifstream f;
f.open(file);
temp = f.good();
f.close();
return temp;
}
bool controllafile(const char* file)
{
char h;
int g = 0;
ifstream f;
f.open(file);
while(!f.eof())
{
f >> noskipws >> h;
if (h!='0' and h!='1' and h!='2' and h!='3' and h!='4' and h!='5' and h!='6' and h!='7' and h!='8' and h!='9' and h!=' ' and h!='.' and h!='\n')
{f.close(); return false;}
if (g++>X*Y) {f.close(); return false;}
if (h=='\n')
{
if (g!=X*Y+1 and g!=1) {f.close(); return false;}
g = 0;
}
}
f.close();
return true;
}
char* sudoku_n(const char* file, int n)
{
ifstream f;
f.open(file);
int length = X*Y;
char *buffer = new char[length];
char invio;
for (int i=0;i<=n;++i)
{
f.read(buffer,length);
f.read(&invio,1);
}
f.close();
return buffer;
}
int contasudoku(const char* file)
{
ifstream f;
char h;
int temp = 0;
f.open(file);
while (!f.eof())
{
f >> noskipws >> h;
if (h == '\n') temp++;
}
if (h=='\n') temp-=2;
f.close();
return temp+1;
}
bool controllasudoku(char sudo[])
{
Scacchiera s(sudo);
return s.corretto();
}