-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrite_to_file_visually.cpp
More file actions
54 lines (43 loc) · 1.48 KB
/
Copy pathwrite_to_file_visually.cpp
File metadata and controls
54 lines (43 loc) · 1.48 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
#include <iostream>
#include <stdio.h>
#include <string.h>
#include "functions_definitions.h"
static int turn_counter = 0;
void write_to_file_visually(const char table[][WIDTH], Player* player_1, Player* player_2)
{
FILE* file;
// Open the file using fopen_s
if (fopen_s(&file, "state_of_the_game_visually.txt", "a") != 0) {
return;
}
fprintf(file, "\n============================\nState of the game at turn %d\n============================\n", turn_counter);
turn_counter++;
fprintf(file, "\n============================\n%s %d points against %s %d points\n============================\n",
player_1->name, player_1->points,
player_2->name, player_2->points);
for (int i = 0; i < HEIGHT; ++i)
{
for (int j = 0; j < WIDTH; ++j)
{
fprintf(file, "%c", table[i][j]);
}
fprintf(file, "\n");
}
// Close the file
fclose(file);
}
static int binary_turn_counter = 0;
void write_to_binary_file(const char table[][WIDTH])
{
FILE* file_binary;
// Open the file in binary write mode
if (fopen_s(&file_binary, "state_of_the_game_binary", "ab") != 0) {
return;
}
fprintf(file_binary, "\n============================\nState of the game at turn %d\n============================\n", binary_turn_counter);
binary_turn_counter++;
// Write the array to the file
fwrite(table, sizeof(char), HEIGHT * WIDTH, file_binary);
// Close the file
fclose(file_binary);
}