-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
95 lines (78 loc) · 2.46 KB
/
Copy pathmain.c
File metadata and controls
95 lines (78 loc) · 2.46 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**
* @file main.c
* @author Afonso Corte-Real (a31500@alunos.ipca.pt)
* @brief Main program implementation for grid graph character processing
* @version 0.2
* @date 26-03-2025
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "include/input.h"
#include "include/calculate.h"
#include "include/matrix.h"
#include "include/graph.h"
/**
* @brief Main function that coordinates program execution
*
* @return int Exit status code (0 for success)
*/
int main() {
// Import grid data from file
GridGraph graph = importFromFile("assets/input.txt");
// Print the grid dimensions
printf("Grid dimensions: %d rows x %d columns\n", graph.rows, graph.cols);
// Print the original grid
printf("\nOriginal Grid:\n");
if (!printGrid(graph)) {
fprintf(stderr, "Error printing grid\n");
return 1;
}
// Process same characters and place '#' at the calculated coordinates
int pointsAdded = processSameCharacters(&graph);
printf("Added %d interference points\n", pointsAdded);
// Print the updated grid
printf("\nUpdated Grid:\n");
if (!printGrid(graph)) {
fprintf(stderr, "Error printing grid\n");
return 1;
}
// Remove all '#' markers
removeAllChar(&graph, '#');
// Remove all 'O' characters
removeAllChar(&graph, 'O');
// Calculate new interference points
processSameCharacters(&graph);
// Print the updated grid
printf("\nUpdated Grid (after removal):\n");
if (!printGrid(graph)) {
fprintf(stderr, "Error printing grid\n");
return 1;
}
// Insert new characters
setCharAtPosition(&graph, 'X', 4, 7);
setCharAtPosition(&graph, 'X', 6, 5);
// Calculate new interference points
processSameCharacters(&graph);
printf("\nUpdated Grid (after insertion):\n");
if (!printGrid(graph)) {
fprintf(stderr, "Error printing grid\n");
return 1;
}
// Create a graph from the grid data
Graph* antennaGraph = createGraphFromGrid(&graph);
if (antennaGraph != NULL) {
destroyGraph(antennaGraph);
}
// Create a graph with adjacency connections
Graph* adjGraph = createAdjacencyGraphFromGrid(&graph);
if (adjGraph != NULL) {
destroyGraphVerbose(adjGraph, false);
}
// Free the grid graph
if (!destroyGridGraph(&graph)) {
fprintf(stderr, "Error destroying grid graph\n");
return 1;
}
return 0;
}