#include #include #include #include #include "colors.h" #define BLOCK_SIZE 8 int main(int argc, char* argv[]) { if (argc < 2) { printf("Usage: %s \n", argv[0]); return 1; } FILE* fp = fopen(argv[1], "rb"); uint8_t buffer[BLOCK_SIZE]; int ok = fread(buffer, sizeof(uint8_t)*2, 1, fp); printf("Dernier cours du semestre précédent: %u.%u\n", buffer[0], buffer[1]); if (!ok) { fclose(fp); return 0; } while (fread(buffer, sizeof(uint8_t)*8, 1, fp)) { printf("\nLe " BLUE "%u/%u/%u" RESET ":\n", buffer[0], buffer[1], buffer[2]); printf("Prix d'ouverture: %u.%u\n", buffer[5], buffer[6]); printf("Prix de clôture: %u.%u\n", buffer[3], buffer[4]); if (buffer[7]) { if (buffer[7] == 1) { fread(buffer, sizeof(uint8_t)*2, 1, fp); printf("Variation: " BOLD GREEN "+%d.%u%%" RESET "\n", buffer[0], buffer[1]); } else if (buffer[7] == 2) { fread(buffer, sizeof(uint8_t)*2, 1, fp); printf("Variation: " BOLD RED "-%d.%u%%" RESET "\n", buffer[0], buffer[1]); } else { printf("Signe de variation inconnu (%d)\n", buffer[7]); return 1; } } fread(buffer, sizeof(uint8_t)*4, 1, fp); printf("Prix maximum: %u.%u\n", buffer[0], buffer[1]); printf("Prix minimum: %u.%u\n", buffer[2], buffer[3]); } }