62 lines
1.0 KiB
C
62 lines
1.0 KiB
C
/*
|
|
* EX20
|
|
* VAN DAMME Adrien
|
|
* Grp 2
|
|
* La fct fgets permet de récuperer une chaine de caractère de façon sécurisée
|
|
*
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <conio.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
|
|
#define __STR_LENGHT__ 20
|
|
|
|
int LireMots(char *, char **);
|
|
int trier (char **);
|
|
int cmpstr(char *, char *);
|
|
int affTab(char **);
|
|
|
|
int main() {
|
|
char tab[20][20];
|
|
char chemin[20] = "tt.txt";
|
|
LireMots(chemin, tab);
|
|
affTab(tab);
|
|
trier(tab);
|
|
affTab(tab);
|
|
return 0;
|
|
}
|
|
|
|
|
|
int LireMots(char *chemin, char **tab)
|
|
{
|
|
int i;
|
|
char c[__STR_LENGHT__];
|
|
char *p;
|
|
FILE * fi;
|
|
if((fi=fopen(chemin, "r")) == NULL)
|
|
return -1;
|
|
for(i=0;i<20;i++)
|
|
{
|
|
fgets(c, 20,fi);
|
|
p = strchr(c, '\n');
|
|
if(p)*p = 0;
|
|
strcpy(((char*)tab+(i*20)),c);
|
|
}
|
|
return 0;
|
|
}
|
|
int trier(char **tab)
|
|
{
|
|
qsort(tab,20,20,cmpstr);
|
|
}
|
|
int affTab(char **tab)
|
|
{
|
|
int i=0;
|
|
for(i=0;i<20;i++)
|
|
printf("%s\n", ((char*)tab+(i*20)));
|
|
}
|
|
int cmpstr(char *a, char *b) {
|
|
return strcmp(a, b);
|
|
}
|