44 lines
970 B
C
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;
|
|
} |