examen fini
This commit is contained in:
9
examen/T1/Makefile
Normal file
9
examen/T1/Makefile
Normal file
@@ -0,0 +1,9 @@
|
||||
CC = gcc
|
||||
|
||||
all: main
|
||||
|
||||
main:
|
||||
$(CC) *.c *.h
|
||||
|
||||
clean:
|
||||
rm a.out
|
||||
52
examen/T1/StatistiqueFichier.c
Normal file
52
examen/T1/StatistiqueFichier.c
Normal file
@@ -0,0 +1,52 @@
|
||||
#include "StatistiqueFichier.h"
|
||||
#include <stdio.h>
|
||||
|
||||
ASCII_table init_table()
|
||||
{
|
||||
ASCII_table table;
|
||||
for (int i = 0; i < 256; i++)
|
||||
{
|
||||
table.ASCII[i] = 0;
|
||||
}
|
||||
return table;
|
||||
}
|
||||
|
||||
void print_ASCII_table(ASCII_table *table)
|
||||
{
|
||||
for (int i = 32; i <= 126; i++)
|
||||
{
|
||||
printf("%d ", table->ASCII[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void print_StatistiqueResultats(ASCII_table *table)
|
||||
{
|
||||
for (int i = 32; i <= 126; i++)
|
||||
{
|
||||
if (table->ASCII[i])
|
||||
{
|
||||
printf("%c: %d\n", i, table->ASCII[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ASCII_table *StatistiqueFichier(char *nomFichier, ASCII_table *table)
|
||||
{
|
||||
FILE *pFile;
|
||||
char c;
|
||||
|
||||
if (pFile = fopen(nomFichier, "rt"))
|
||||
{
|
||||
for (c = fgetc(pFile); !feof(pFile); c = fgetc(pFile))
|
||||
{
|
||||
table->ASCII[(int)c]++;
|
||||
}
|
||||
fclose(pFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("error");
|
||||
}
|
||||
return table;
|
||||
}
|
||||
9
examen/T1/StatistiqueFichier.h
Normal file
9
examen/T1/StatistiqueFichier.h
Normal file
@@ -0,0 +1,9 @@
|
||||
typedef struct ASCII_table
|
||||
{
|
||||
int ASCII[256];
|
||||
} ASCII_table;
|
||||
|
||||
ASCII_table init_table();
|
||||
ASCII_table *StatistiqueFichier(char *nomFichier, ASCII_table *table);
|
||||
void print_ASCII_table(ASCII_table *table);
|
||||
void print_StatistiqueResultats(ASCII_table *table);
|
||||
8
examen/T1/fichier.txt
Normal file
8
examen/T1/fichier.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
abcdefg
|
||||
abcdefg
|
||||
abcdefg
|
||||
abcdefg
|
||||
,/df,glsd,lrekg
|
||||
}{}:":L:
|
||||
sdkljflskjdflkajlk. fdjsakljflwa
|
||||
jgriej. giojgrekrjkdskjfklwjk
|
||||
11
examen/T1/main.c
Normal file
11
examen/T1/main.c
Normal file
@@ -0,0 +1,11 @@
|
||||
#include "StatistiqueFichier.h"
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
ASCII_table table;
|
||||
table = init_table();
|
||||
StatistiqueFichier("fichier.txt", &table);
|
||||
print_StatistiqueResultats(&table);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user