APL/APL1.2/TP10/balises.c
2022-01-18 15:45:21 +01:00

44 lines
970 B
C

#include <stdio.h>
#include <stdlib.h>
#include "chainee.c"
int isBal(char c) {
return (c == '<') || (c == '>');
}
int opening(char c) {
return (c == '<');
}
int isMatching(char a, char b) {
return (a == '<' && b == '>');
}
int main(int argc, char* argv[]) {
FILE* f = fopen(argv[1], "r");
pile p;
if (f) {
int valid = 1;
while (!feof(f)) {
char c = fgetc(f);
if (isBal(c)) {
if (opening(c)) push(&p, c);
else {
char par = pop(&p);
if (!isMatching(par, c)) {
printf("Le fichier %s est mal balisé !\n", argv[1]);
valid = 0;
break;
}
}
}
}
if (valid) printf("Le fichier %s est bien balisé !\n", argv[1]);
fclose(f);
} else puts("Error opening file.");
return EXIT_SUCCESS;
}