// Laboratorio 8 - Esercizio 2 - main.c // Matteo Schiff - s295565 #include #include #include"Graph.h" #define MAX_LEN 30 const int MAXL = 100; typedef enum { r_print, r_adj, r_build, r_fine } t_comandi; char *toLower(char *s) { for (char *p = s; *p; p++) *p = tolower(*p); return s; } t_comandi leggiComando() { t_comandi c; char cmd[MAXL]; char tabella[4][20] = { "stampa", "adiacenza", "converti", "fine"}; printf("comando (stampa/adiacenza/converti/fine): "); scanf("%s", cmd); toLower(cmd); c = r_print; while (c < 4 && strcmp(cmd, tabella[c]) != 0) c++; return (c); } void menuParola(Graph G) { t_comandi comando; int i, continua = 1; while (continua) { comando = leggiComando(); switch (comando) { case r_print: GRAPHprintOrdered(G); break; case r_adj: GRAPHCheckVertexAdiacency(G); break; case r_build: GRAPHbuildLadj(G); break; case r_fine: continua = 0; break; default: puts("Comando non valido\n"); } } } int main(int argc, char const *argv[]) { FILE * fp_read; Graph G; if (argc < 1) { puts("Specifica il file tra gli argomenti"); return 1; } if ((fp_read = fopen(argv[1], "r")) == NULL) { puts("Impossibile aprire il file"); return 1; } G = GRAPHload(fp_read); fclose(fp_read); menuParola(G); GRAPHfree(G); return 0; }