Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- /*1)Soit un fichier LIVRE contenant sur chacun de ses enregistrements le titre(chaîne),
- la collection(chaîne) et l’année de parution. On vous demande d’afficher à l’écran le contenu de ce fichier
- et d’afficher à la fin du programme le titre du livre le plus ancien (ne pas utiliser de tableau).
- */
- struct livre
- {
- char titre[50],collection[50];
- int annee;
- };
- int main()
- {
- int i=0,min=2021,flag=0;
- FILE *f;
- struct livre a;
- f=fopen("livre.dat","w");
- if(f!=NULL)
- {
- do
- {
- fflush(stdin);
- printf("\nTitre %d: ",i+1);
- gets(a.titre);
- if(strcmpi(a.titre,"*")!=0)
- {
- printf("\nCollection : ");
- gets(a.collection);
- printf("\nAnnee : ");
- scanf("%d",&a.annee);
- if(a.annee<min)
- {
- min=a.annee;
- }
- i++;
- }
- else
- {
- flag=1;
- }
- }
- while(flag!=1 && i<5);
- if(i>0)
- {
- printf("\nL'annee du livre le plus ancien est : %d\n",min);
- }
- fclose(f);
- }
- else
- {
- printf("\nProbleme d'ouverture\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement