Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. /*1)Soit un fichier LIVRE contenant sur chacun de ses enregistrements le titre(chaîne),
  6. la collection(chaîne) et l’année de parution. On vous demande d’afficher à l’écran le contenu de ce fichier
  7. et d’afficher à la fin du programme le titre du livre le plus ancien (ne pas utiliser de tableau).
  8. */
  9.  
  10. struct livre
  11. {
  12. char titre[50],collection[50];
  13. int annee;
  14. };
  15.  
  16. int main()
  17. {
  18. int i=0,min=2021,flag=0;
  19. FILE *f;
  20. struct livre a;
  21. f=fopen("livre.dat","w");
  22.  
  23. if(f!=NULL)
  24. {
  25. do
  26. {
  27. fflush(stdin);
  28. printf("\nTitre %d: ",i+1);
  29. gets(a.titre);
  30. if(strcmpi(a.titre,"*")!=0)
  31. {
  32. printf("\nCollection : ");
  33. gets(a.collection);
  34.  
  35. printf("\nAnnee : ");
  36. scanf("%d",&a.annee);
  37. if(a.annee<min)
  38. {
  39. min=a.annee;
  40. }
  41. i++;
  42. }
  43. else
  44. {
  45. flag=1;
  46.  
  47. }
  48. }
  49. while(flag!=1 && i<5);
  50.  
  51. if(i>0)
  52. {
  53. printf("\nL'annee du livre le plus ancien est : %d\n",min);
  54. }
  55. fclose(f);
  56. }
  57. else
  58. {
  59. printf("\nProbleme d'ouverture\n");
  60. }
  61.  
  62. return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement