1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| int triFlots(FILE *flotLecture, FILE *flotEcriture,
int (*cmp)(const char *s1, const char *s2))
{
char ligne[256];
char *mot;
Heap *h;
char *res;
int nbElts = 0;
if(flotLecture != NULL)
{
if(newHeap(&h,cmp))
{
fprintf(stderr,"erreur\n");
return 1;
}
while(fgets(ligne, sizeof ligne, flotLecture) != NULL)
{
if(addToHeap(h,ligne))
{
fprintf(stderr,"erreur\n");
return 1;
}
nbElts++;
}
while(nbElts != 0)
{
if(removeSmallestFromHeap(h,res))
{
fprintf(stderr,"erreur\n");
return 1;
}
fprintf(flotEcriture,"%s",res);
nbElts--;
}
freeHeap(&h);
}
return 0;
} |
Partager