commit 6a109dd796543394f0bcf959051ffc233d481cc4 Author: Mattéo Delabre Date: Wed Oct 5 12:52:58 2016 +0200 Initial commit diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d2f077d --- /dev/null +++ b/Makefile @@ -0,0 +1,13 @@ +CC=gcc +FLAGS=-Wall -std=c99 +SRC=src +PROG=compress + +all: $(SRC)/main.o $(SRC)/freq.o + $(CC) $^ $(FLAGS) -o $(PROG) + +%.o: %.cpp + $(CC) $(FLAGS) -c $^ + +camille: + rm -f $(PROG) *.o *.gch diff --git a/data/test.txt b/data/test.txt new file mode 100644 index 0000000..e5b7d73 --- /dev/null +++ b/data/test.txt @@ -0,0 +1 @@ +Lorem ipsum dolor sit amet, consectetur adipiscing elit. In viverra est a est luctus, at euismod elit tempus. Maecenas ut auctor lectus, vitae vestibulum est. Nunc id libero tempor, posuere purus laoreet, vehicula sem. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Curabitur porttitor turpis faucibus diam varius, nec venenatis leo gravida. Nulla facilisi. Etiam pellentesque tortor sed urna faucibus venenatis. Nullam pulvinar nunc ut orci sodales, molestie maximus dui suscipit. Mauris commodo vestibulum egestas. Vestibulum tincidunt facilisis diam, in sollicitudin dolor sodales vitae. Sed sit amet sapien ipsum. Fusce non dolor quis mauris lacinia posuere. Nunc semper orci libero, eget fringilla lectus ornare eget. Sed volutpat purus vitae risus mattis auctor. Curabitur auctor pharetra rutrum. Nulla fermentum nulla libero, quis rhoncus elit placerat et. Fusce at sapien vel neque iaculis cursus. Nulla congue massa nec dui finibus, quis tincidunt risus vehicula. Sed fringilla fringilla enim nec ullamcorper. Fusce in velit quis urna semper malesuada. Curabitur id augue in felis fringilla vehicula. Proin facilisis turpis ac ligula euismod, sed consectetur felis lobortis. Sed vehicula eget ex vitae lacinia. Sed lectus nunc, iaculis non nunc sed, imperdiet commodo urna. Suspendisse semper gravida convallis. Morbi ut ligula efficitur, scelerisque purus ut, tincidunt ante. Nam rhoncus ante vel orci accumsan, at laoreet sapien dapibus. Aliquam quis dolor eget ex fermentum malesuada. In non dictum metus. Donec sed nisl finibus, accumsan magna at, lobortis nunc. Sed congue euismod velit eu ullamcorper. Aenean scelerisque odio sapien, rutrum aliquet erat elementum vitae. Cras sed egestas massa, id vestibulum urna. Nam maximus ligula et nulla condimentum, ac hendrerit ante fermentum. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam tempus nisi sed felis eleifend, in molestie quam ullamcorper. Nulla in enim volutpat, porta metus. \ No newline at end of file diff --git a/main.c b/main.c new file mode 100644 index 0000000..9185482 --- /dev/null +++ b/main.c @@ -0,0 +1,9 @@ +#include "freq.h" +#include + +int main(int argc, char** argv) { + if (argc != 2) { + printf("Usage : compress \n") + printf("Paramètre fichier manquant.\n"); + } +} diff --git a/src/freq.c b/src/freq.c new file mode 100644 index 0000000..b27e328 --- /dev/null +++ b/src/freq.c @@ -0,0 +1,29 @@ +#include "freq.h" +#include +#include + +double* computeFreq(const char* filepath) { + double* freq = (double*) malloc(256 * sizeof(double)); + int totalChars = 0; + + // initialisation du tableau à 0 + for (int i = 0; i < 256; i++) { + freq[i] = 0; + } + + // parcours du fichier et comptage des caractères + FILE* file = fopen(filepath, "r"); + char current; + + while ((current = fgetc(file)) != EOF) { + freq[(size_t) current]++; + totalChars++; + } + + // conversion des effectifs en fréquences + for (int i = 0; i < 256; i++) { + freq[i] /= totalChars; + } + + return freq; +} diff --git a/src/freq.h b/src/freq.h new file mode 100644 index 0000000..a44cb1d --- /dev/null +++ b/src/freq.h @@ -0,0 +1 @@ +double* computeFreq(const char* filepath); diff --git a/src/freq.o b/src/freq.o new file mode 100644 index 0000000..2a9d54d Binary files /dev/null and b/src/freq.o differ diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..e69de29 diff --git a/src/main.o b/src/main.o new file mode 100644 index 0000000..fac15cc Binary files /dev/null and b/src/main.o differ