© Éditions Eyrolles
259
Correction des exercices
entree = fopen (nomfich, "r") ;
fseek (entree, 0, SEEK_END) ; taille = ftell(entree) ;
printf (" quel numéro recherchez-vous : ") ;
scanf ("%d",&num) ;
pos = num * sizeof(bloc) ;
if ( num<0 || pos >= taille )
printf ("-- ce numéro ne figure pas dans le fichier ") ;
else
{ fseek (entree, pos, 0 ) ;
fread (&bloc, sizeof(bloc), 1, entree) ;
printf ("nom
: %s\n", bloc.nom) ;
printf ("prénom
: %s\n", bloc.prenom) ;
printf ("age
: %d\n", bloc.age) ;
printf ("téléphone : %s\n", bloc.tel) ;
}
}
CHAPITRE 11
Exercice 11.1
#include
#include
typedef struct element { int num ;
float x ;
float y ;
struct element * suivant ;
} s_point ;
void creation (s_point * * adeb) ;
void liste
(s_point * debut) ;
main()
{
s_point * debut ;
creation (&debut) ;
liste(debut) ;
}
Delannoy Livre.book Page 259 Mercredi, 6. mai 2009 4:27 16
259
Correction des exercices
entree = fopen (nomfich, "r") ;
fseek (entree, 0, SEEK_END) ; taille = ftell(entree) ;
printf (" quel numéro recherchez-vous : ") ;
scanf ("%d",&num) ;
pos = num * sizeof(bloc) ;
if ( num<0 || pos >= taille )
printf ("-- ce numéro ne figure pas dans le fichier ") ;
else
{ fseek (entree, pos, 0 ) ;
fread (&bloc, sizeof(bloc), 1, entree) ;
printf ("nom
: %s\n", bloc.nom) ;
printf ("prénom
: %s\n", bloc.prenom) ;
printf ("age
: %d\n", bloc.age) ;
printf ("téléphone : %s\n", bloc.tel) ;
}
}
CHAPITRE 11
Exercice 11.1
#include
#include
typedef struct element { int num ;
float x ;
float y ;
struct element * suivant ;
} s_point ;
void creation (s_point * * adeb) ;
void liste
(s_point * debut) ;
main()
{
s_point * debut ;
creation (&debut) ;
liste(debut) ;
}
Delannoy Livre.book Page 259 Mercredi, 6. mai 2009 4:27 16
