-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibrary.cpp
More file actions
73 lines (66 loc) · 1.77 KB
/
Copy pathlibrary.cpp
File metadata and controls
73 lines (66 loc) · 1.77 KB
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
#include "library.h"
//TODO: добавить проверку на успешность открытия файла
char** getMatrix(string way_to_file){
ifstream file;
file.open(way_to_file);
//Находим размерность матрицы
int lines = countNumberOfLines(way_to_file);
int columns = countNumberOfColumns(way_to_file);
//Создание матрицы-лабиринта
char **matrix = new char*[lines];
for(int i = 0; i < lines; i++){
matrix[i] = new char[columns];
}
//Заполнение матрицы, не учитывая пробелы
for(int i = 0; i < lines; i++){
for(int j = 0; j < 2*columns; j++){
if(j==2*columns-1) {
char tmp;
tmp = file.get();
continue;
}
if(j % 2 == 0){
matrix[i][j/2] = file.get();
}
else{
char tmp;
tmp = file.get();
}
}
}
file.close();
return matrix;
}
int countNumberOfLines(string way_to_file){
int result = 0;
ifstream file;
file.open(way_to_file);
while(!file.eof()){
string tmp = "";
getline(file, tmp);
result += 1;
}
file.close();
return result;
}
int countNumberOfColumns(string way_to_file){
int result = 0;
ifstream file;
file.open(way_to_file);
char tmp = ' ';
//Ищем количество символов в строке
while(tmp != '\n'){
tmp = ' ';
tmp = file.get();
result += 1;
}
//Учитываем пробелы в строке
if(result % 2 == 0){
result /= 2;
}
else{
result /= 2 + 1;
}
file.close();
return result;
}