Skip to content
Extraits de code Groupes Projets
Valider c1458fe9 rédigé par Anteunis Charles's avatar Anteunis Charles
Parcourir les fichiers

fix fgetchar, add Makefile

parent 30cf9752
Branches
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
CC=gcc -Wall -Wextra -ansi
TARGET=prog2d
OBJ=interpreteur.o list.o
all: $(TARGET)
$(TARGET): $(OBJ)
$(CC) main.c $^ -o $(TARGET)
%.o: %.c %.h
$(CC) -c $<
interpreteur.o: interpreteur.c interpreteur.h list.h
$(CC) -c $<
clean:
rm $(OBJ) $(TARGET)
re: clean all
\ No newline at end of file
Fichier supprimé
#include "interpreteur.h" #include "interpreteur.h"
#include <stdio.h>
#include <stdlib.h>
/**
* \brief tronque un entier entre 0 et 255
*/
int troncate(int n) { int troncate(int n) {
if (n<0) if (n<0)
return 0; return 0;
...@@ -9,6 +14,9 @@ int troncate(int n) { ...@@ -9,6 +14,9 @@ int troncate(int n) {
return n; return n;
} }
/**
* \brief interprete le fichier d'entrée en déplaçant le curseur
*/
void interpreteur(char **matrix, int height, int width) { void interpreteur(char **matrix, int height, int width) {
curseur cur; curseur cur;
int i, j, a, b; int i, j, a, b;
...@@ -20,25 +28,25 @@ void interpreteur(char **matrix, int height, int width) { ...@@ -20,25 +28,25 @@ void interpreteur(char **matrix, int height, int width) {
char buf[256]; char buf[256];
char *endptr; char *endptr;
/* initialise le module random */ /* initialisation du module random */
srand((unsigned) time(&t)); srand((unsigned) time(&t));
cur.x = 0; cur.x = 0;
cur.y = 0; cur.y = 0;
/* on commence en haut à gauche, direction à droite */
cur.current_char = matrix[0][0]; cur.current_char = matrix[0][0];
cur.current_dir = E; cur.current_dir = E;
while (cur.current_char != '@') { while (cur.current_char != '@') {
printf("=-=-=-=-=-=-=\n"); /*printf("=-=-=-=-=-=-=\n");
printf("current char: %i = %c\n", cur.current_char, cur.current_char); printf("current char: %i = %c\n", cur.current_char, cur.current_char);*/
/* Action en fonction du caractère lu */ /* Action en fonction du caractère lu */
/* Si on est sur un pont, on ne lit pas l'instruction et on avance sur le pont */ /* Si on est sur un pont, on ne lit pas l'instruction et on avance sur le pont */
if (bridge) if (bridge)
{ {
bridge--; bridge--;
} }
/* Si on est en mode chaine de caractere on empile ce qu'on lit */ /* Si on est en mode chaine de caractere on empile ce qu'on lit */
...@@ -47,13 +55,11 @@ void interpreteur(char **matrix, int height, int width) { ...@@ -47,13 +55,11 @@ void interpreteur(char **matrix, int height, int width) {
string_mode = 1 - string_mode; string_mode = 1 - string_mode;
else else
push(cur.current_char, &pile); push(cur.current_char, &pile);
} }
else { else {
/* switch pour les actions en fonction du caractère lu */
switch (cur.current_char) switch (cur.current_char)
{ {
case '+': case '+':
a = pop(&pile); a = pop(&pile);
b = pop(&pile); b = pop(&pile);
...@@ -240,7 +246,7 @@ void interpreteur(char **matrix, int height, int width) { ...@@ -240,7 +246,7 @@ void interpreteur(char **matrix, int height, int width) {
case '~': case '~':
printf("Veuillez entrer un caratere\n"); printf("Veuillez entrer un caratere\n");
tmp = fgetchar(); tmp = getchar();
push(tmp, &pile); push(tmp, &pile);
break; break;
...@@ -309,16 +315,11 @@ void interpreteur(char **matrix, int height, int width) { ...@@ -309,16 +315,11 @@ void interpreteur(char **matrix, int height, int width) {
cur.current_char = matrix[cur.y][cur.x]; cur.current_char = matrix[cur.y][cur.x];
print_list(pile); /*print_list(pile);
//printf("string_mode: %i\n", string_mode); printf("string_mode: %i\n", string_mode);
//printf("bridge: %i\n", bridge); printf("bridge: %i\n", bridge);*/
} }
printf("Contenu de la pile :\n");
while (!is_empty(pile))
{
printf("%i, ", pop(&pile));
}
printf("Fin de l'interpreteur\n"); printf("Fin de l'interpreteur\n");
} }
\ No newline at end of file
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter