Disclaimer: some words in my code are in French.
When I compile my code there is no bug, but when I run it the only thing that appears is the sentence "Contenu du tableau avant le tri". I think the file I need to read (notes.txt) isn't being read. Anyone has any idea what the problem is? Here's my code:
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#define MAX_PERS 200
typedef struct
{
int numero;
float note;
char nom, prenom;
} donnees;
donnees tab[MAX_PERS];
int nbPers=0;
void lire(donnees tab[], int *n)
{
FILE *aLire = fopen("notes.txt", "r");
int nb=0;
while(!feof(aLire))
{
fscanf(aLire, "%d%s%s%f\n", &tab[nb].numero, &tab[nb].nom, &tab[nb].prenom, &tab[nb].note);
nb++;
}
fclose(aLire);
*n = nb;
}
void afficher(donnees tab[], int nb, char *quand)
{
int i;
printf("Contenu du tableau %s le tri\n\n", quand);
for(i=0; i<nb; i++)
printf( "%4d %15s %15s %2.2f\n", tab[i].numero, tab[i].nom, tab[i].prenom, tab[i].note);
}
void echanger (donnees *P1, donnees *P2)
{
donnees tempo;
tempo = *P1 ;
*P1 = *P2;
*P2 = tempo;
}
void partitionner ( donnees tab[], int debut, int fin, int *P )
{
int G = debut , D = fin ;
float Val_Pivot = tab[debut].note;
while ( G <= D && tab[G].note <= Val_Pivot) G++;
while ( tab[D].note > Val_Pivot) D--;
if ( G < D ) echanger(&tab[G], &tab[D]);
while ( G <= D ) ;
*P = D ;
echanger (&tab[debut], &tab[D]);
}
void quickSort ( donnees tab[], int gauche, int droite )
{
int indPivot ;
if (droite > gauche)
{
partitionner ( tab, gauche, droite, &indPivot);
quickSort ( tab, gauche, indPivot - 1 );
quickSort ( tab, indPivot + 1, droite);
}
}
int main()
{
donnees tab[MAX_PERS];
lire(tab, &nbPers);
afficher(tab, nbPers, "avant");
return 0;
}