Notions de fichiers

Christy SB Messages postés 4 Statut Membre -  
Christy SB Messages postés 4 Statut Membre -
je veux creer un fichier nomme "biblio"et creer dans le fichier biblio 5 autres fichiers: biblio1, biblio2, biblio3, biblio4, biblio5. Dans chacun des 5 fichiers est stocke des informations. J'aimerais aussi pouvoir modifier les elements contenus dans les fichiers biblio1,biblio2, biblio3, biblio4 et biblio5.

4 réponses

  1. fiddy Messages postés 441 Date d'inscription   Statut Contributeur Dernière intervention   1 847
     
    Oui la politesse est la bienvenue...
    Il va falloir être plus précis et nous dire le rapport avec le C.
    Montre-nous aussi ce que tu as commencé à faire
    Et dis-nous où tu bloques.
    1
  2. Christy SB Messages postés 4 Statut Membre
     
    Merci, deja!!!
    0
  3. Christy SB Messages postés 4 Statut Membre
     
    Merci fiddy!
    Voici le travail que g commence

    #include <stdio.h>
    #include <stdlib.h>
    #include <ctype.h>
    #include <string.h>
    #include <time.h>

    int main()
    {
    //--------------------------------------------------------------------------------
    char titre[20],genre[30],auteur[40],rayon[20];
    int isbn=0;
    int code[2];
    char code_m[8],code_E[8];
    int nbre=rand()%99;
    int i=0,n=0;
    char choix,repond;
    char nom_m[25],prenom_m[30],sexe_m[1];
    char nom_E[25],prenom_E[30],sexe_E[1];
    char chaine1[2],chaine2[2];

    //--------------------------------------------------------------------------------
    // MENU PRINCIPAL
    printf("\n\n ----------------------------");
    printf(" |=====================================================|\n");
    printf(" |=====================================| \n");
    printf(" |========================================================|\n");
    printf(" |===================================================|\n");
    printf(" |==========================================|\n");
    do
    {
    printf(" |===============================Bibliotheque=================================|\n\n");
    printf(" |-----------------------------|*\n");
    printf(" | A.Livre | *\n");
    printf(" |-----------------------------| *\n");
    printf(" | B.Membre | *\n");
    printf(" |-----------------------------| *\n");
    printf(" | C.Emprunt | *\n");
    printf(" |-----------------------------|*\n");
    printf(" |Lettre:");
    scanf("%s",&choix);

    switch(choix)
    {
    //--------------------------------------------------------------------------------
    //CASE DE SOUS-MENU DU LIVRE
    case 'A' :printf("\n Votre choix est livre:\n");
    char choixl;
    printf(" |---------------------------------");
    printf("\n | a.Enregistrer livre\n");
    printf(" |---------------------------------\n");
    printf(" | b.Afficher livre\n");
    printf(" |---------------------------------");
    printf("\n | c.Rechercher livre\n");
    printf(" |---------------------------------");
    printf("\n | d.Modifier les champs de livre\n");
    printf(" |---------------------------------");
    printf("\n | e.Eliminer un livre \n");
    printf(" |---------------------------------");
    printf("\n\n |---------------------------------\n");
    printf(" | Faites votre choix!");
    printf("\n |---------------------------------");
    printf("\n | Lettre : ");
    scanf("%s",&choixl);

    switch(choixl)
    {
    //--------------------------------------------------------------------------------
    //CASES D'INSERSION LIVRE DANS DIFFERENT RAYON
    char choixdep;
    case 'a' :printf("\n Votre choix est d'enregistrer un livre!!!\n\n");
    printf("\n Combien de livre voulez-vous enrgistrer?\n");
    printf("\n Nombre: ");
    scanf("%d",&n);
    printf("\n Vous inserez dans quel rayon!\n\n");

    printf(" |-----------------------------|*\n");
    printf(" | A.Histoire et bonne aventure| *\n");
    printf(" |-----------------------------| *\n");
    printf(" | B.Sciences fictions | *\n");
    printf(" |-----------------------------| *\n");
    printf(" | C.Sciences | *\n");
    printf(" |-----------------------------| *\n");
    printf(" | D.Magie | *\n");
    printf(" |-----------------------------| *\n");
    printf(" | E.Sexologie | *\n");
    printf(" |-----------------------------|*\n");
    printf("\n\n |----------------------------|\n");
    printf(" |Faites votre choix (1 ou 2) |\n");
    printf(" |-----------------------------|\n");
    printf(" |Lettre:");
    scanf("%s",&choixdep);

    switch(choixdep)
    {
    //--------------------------------------------------------------------------------
    case 'A' :printf("\n Vous inserez dans le rayon'Histoire et bonne aventure':\n");
    FILE *biblio=NULL;
    biblio=fopen("C:/Users/PhiserDie_@Phita/Desktop/projet final C/projet final/livreHBA.txt","a+");

    for(i=1; i<=n; i++)
    {
    printf("\n");
    printf("\n Entrer 'titre du livre' :");
    scanf("%s",titre);
    printf("\n Entrer 'Genre du livre' :");
    scanf("%s",genre);
    printf("\n Entrer 'Auteur du livre' :");
    scanf("%s",auteur);
    printf("\n Entrer 'Rayon livre' :");
    scanf("%s",rayon);
    printf("\n Entrer 'ISBN du livre' :");
    scanf("%d",&isbn);

    strcpy(chaine1,titre);
    strcpy(chaine2,genre);
    strcat(chaine1,chaine2);
    //nbre[10]=rand();
    //strcat(chaine1,nbre);

    fprintf(biblio,"\n\n Fiche technique livre du rayon'Histoire et bonne aventure'!!!");
    fprintf(biblio,"\nTitre Livre :%s",titre);
    fprintf(biblio,"\nGenre Livre :%s",genre);
    fprintf(biblio,"\nAuteur Livre :%s",auteur);
    fprintf(biblio,"\nRayon Livre :%s",rayon);
    fprintf(biblio,"\nISBN Livre :%d",isbn);
    fprintf(biblio,"\nCode Livre :%s %d",chaine1,nbre);
    }
    fclose(biblio);

    break;
    //--------------------------------------------------------------------------------
    case 'B' :printf("\n Vous inserez dans le rayon'Sciences fictions':\n");
    FILE *biblioS_C=NULL;
    biblioS_C=fopen("C:/Users/PhiserDie_@Phita/Desktop/projet final C/projet final/livreS.C.txt","a+");

    for(i=1; i<=n; i++)
    {
    printf("\n");
    printf("\n Entrer 'titre du livre' :");
    scanf("%s",titre);
    printf("\n Entrer 'Genre du livre' :");
    scanf("%s",genre);
    printf("\n Entrer 'Auteur du livre' :");
    scanf("%s",auteur);
    printf("\n Entrer 'Rayon livre' :");
    scanf("%s",rayon);
    printf("\n Entrer 'ISBN du livre' :");
    scanf("%d",&isbn);
    printf("\n Entrer 'Code du livre' :");
    scanf("%s",code);

    fprintf(biblioS_C,"\n\n Fiche technique livre du rayon'Sciences fictions'!!!");
    fprintf(biblioS_C,"\nTitre Livre :%s",titre);
    fprintf(biblioS_C,"\nGenre Livre :%s",genre);
    fprintf(biblioS_C,"\nAuteur Livre :%s",auteur);
    fprintf(biblioS_C,"\nRayon Livre :%s",rayon);
    fprintf(biblioS_C,"\nISBN Livre :%d",isbn);
    fprintf(biblioS_C,"\nCode Livre :%s",code);
    }
    fclose(biblioS_C);

    break;
    //--------------------------------------------------------------------------------
    case 'C' :printf("\n Vous inserez dans le rayon'Sciences':\n");
    FILE *biblioSI=NULL;
    biblioSI=fopen("C:/Users/PhiserDie_@Phita/Desktop/projet final C/projet final/livreSI.txt","a+");

    for(i=1; i<=n; i++)
    {
    printf("\n");
    printf("\n Entrer 'titre du livre' :");
    scanf("%s",titre);
    printf("\n Entrer 'Genre du livre' :");
    scanf("%s",genre);
    printf("\n Entrer 'Auteur du livre' :");
    scanf("%s",auteur);
    printf("\n Entrer 'Rayon livre' :");
    scanf("%s",rayon);
    printf("\n Entrer 'ISBN du livre' :");
    scanf("%d",&isbn);
    printf("\n Entrer 'Code du livre' :");
    scanf("%s",code);

    fprintf(biblioSI,"\n\n Fiche technique livre du rayon'Sciences'!!!");
    fprintf(biblioSI,"\n Titre Livre :%s",titre);
    fprintf(biblioSI,"\n Genre Livre :%s",genre);
    fprintf(biblioSI,"\n Auteur Livre :%s",auteur);
    fprintf(biblioSI,"\n Rayon Livre :%s",rayon);
    fprintf(biblioSI,"\n ISBN Livre :%d",isbn);
    fprintf(biblioSI,"\n Code Livre :%s",code);
    }
    fclose(biblioSI);

    break;
    //--------------------------------------------------------------------------------
    case 'D' :printf("\n Vous inserez dans le rayon'Magie':\n");
    FILE *biblioM=NULL;
    biblioM=fopen("C:/Users/PhiserDie_@Phita/Desktop/projet final C/projet final/livreM.txt","a+");

    for(i=1; i<=n; i++)
    {
    printf("\n");
    printf("\n Entrer 'titre du livre' :");
    scanf("%s",titre);
    printf("\n Entrer 'Genre du livre' :");
    scanf("%s",genre);
    printf("\n Entrer 'Auteur du livre' :");
    scanf("%s",auteur);
    printf("\n Entrer 'Rayon livre' :");
    scanf("%s",rayon);
    printf("\n Entrer 'ISBN du livre' :");
    scanf("%d",&isbn);
    printf("\n Entrer 'Code du livre' :");
    scanf("%s",code);

    fprintf(biblioM,"\n\n Fiche technique livre du rayon'Magie'!!!");
    fprintf(biblioM,"\n Titre Livre :%s",titre);
    fprintf(biblioM,"\n Genre Livre :%s",genre);
    fprintf(biblioM,"\n Auteur Livre :%s",auteur);
    fprintf(biblioM,"\n Rayon Livre :%s",rayon);
    fprintf(biblioM,"\n ISBN Livre :%d",isbn);
    fprintf(biblioM,"\n Code Livre :%s",code);
    }
    fclose(biblioM);
    break;
    //--------------------------------------------------------------------------------
    case 'E' :printf("\n Vous inserez dans le rayon'Sexologie':\n");
    FILE *biblioS=NULL;
    biblioS=fopen("C:/Users/PhiserDie_@Phita/Desktop/projet final C/projet final/livreS.txt","a+");

    for(i=1; i<=n; i++)
    {
    printf("\n");
    printf("\n Entrer 'titre du livre' :");
    scanf("%s",titre);
    printf("\n Entrer 'Genre du livre' :");
    scanf("%s",genre);
    printf("\n Entrer 'Auteur du livre' :");
    scanf("%s",auteur);
    printf("\n Entrer 'Rayon livre' :");
    scanf("%s",rayon);
    printf("\n Entrer 'ISBN du livre' :");
    scanf("%d",&isbn);
    printf("\n Entrer 'Code du livre' :");
    scanf("%s",code);

    fprintf(biblioS,"\n\n Fiche technique livre du rayon'Sexologie'!!!");
    fprintf(biblioS,"\n Titre Livre :%s",titre);
    fprintf(biblioS,"\n Genre Livre :%s",genre);
    fprintf(biblioS,"\n Auteur Livre :%s",auteur);
    fprintf(biblioS,"\n Rayon Livre :%s",rayon);
    fprintf(biblioS,"\n ISBN Livre :%d",isbn);
    fprintf(biblioS,"\n Code Livre :%s",code);
    }
    fclose(biblioS);
    break;

    default: printf("Mauvais choix, reessayer:\n\n");
    break;
    }
    break;
    //FIN D'INSERSION DANS LA CASE A.
    //--------------------------------------------------------------------------------
    //CASE D'AFFICHAGE DU LIVRE
    case 'b' :printf("\n Votre choix est d'afficher un livre:\n");
    break;
    //FIN DE LA CASE D'AFFICHAGE DU LIVRE
    //--------------------------------------------------------------------------------
    //CASE DE RECHERCHE DU LIVRE.
    case 'c' :printf("\n votre choix est de rechercher un livre:\n");
    break;
    //FIN DE LA CASE DE RECHERCHE DU LIVRE.
    //---------------------------------------------------------------------------------
    //CASE DE MODIFICATION DU LIVRE.
    case 'd' :printf("\n votre choix est de modifier les champs d'un livre :\n");
    break;
    //FIN DE LA CASE DE MODIFICATION DU LIVRE.
    //--------------------------------------------------------------------------------
    //CASE D'ELIMANATION DU LIVRE
    case 'e' :printf("\n votre choix est d'eliminer un livre:\n");
    break;
    //--------------------------------------------------------------------------------
    default: printf("Mauvais choix, reessayer:\n\n");
    }
    break;
    //FIN DE LA CASE DE SOUS-MENU DU LIVRE.
    //********************************************************************************

    // DEBUT DE LA CASE DE SOUS-MENU DE MEMBRE

    case 'B' :printf("\n Votre choix est memre:\n");
    char choixM;
    printf(" |----------------------");
    printf("\n | a.Ajouter un membre\n");
    printf(" |----------------------\n");
    printf(" | b.Afficher un membre\n");
    printf(" |----------------------");
    printf("\n | c.Rechercher un membre\n");
    printf(" |----------------------");
    printf("\n | d.Modifier un membre\n");
    printf(" |----------------------");
    printf("\n | e.Eliminer un membre\n");
    printf(" |----------------------");
    printf("\n\n |----------------------\n");
    printf(" | Faites votre choix!");
    printf("\n |----------------------");
    printf("\n | Lettre : ");
    scanf("%s",&choixM);

    switch(choixM)
    {
    case 'a' :printf("\n Votre choix est d'enregistrer un livre!!!\n\n");
    printf("\n Combien de membre voulez-vous enrgistrer?\n");
    printf("\n Nombre: ");
    scanf("%d",&n);

    FILE *MEMBRE=NULL;
    MEMBRE=fopen("C:/Users/PhiserDie_@Phita/Desktop/projet final C/projet final/membre.txt","a+");

    for(i=1; i<=n; i++)
    {
    printf("\n");
    printf("\n Entrer 'Nom du membre' :");
    scanf("%s",nom_m);
    printf("\n Entrer 'Prenom du membre':");
    scanf("%s",prenom_m);
    printf("\n Entrer 'Sexe du membre' :");
    scanf("%s",sexe_m);
    printf("\n Entrer 'Code du membre' :");
    scanf("%s",code_m);

    fprintf(MEMBRE,"\n\n Fiche technique du membre!!!");
    fprintf(MEMBRE,"\n Nom membre :%s",nom_m);
    fprintf(MEMBRE,"\n Prenom membre:%s",prenom_m);
    fprintf(MEMBRE,"\n Sexe membre :%s",sexe_m);
    fprintf(MEMBRE,"\n Code membre :%s",code);
    }
    fclose(MEMBRE);
    break;

    case 'b' :printf("\n Votre choix est d'afficher membre:\n");
    break;

    case 'c' :printf("\n votre choix est de rechercher un membre:\n");
    break;

    case 'd' :printf("\n votre choix est de modifier un membre :\n");
    break;

    case 'e' :printf("\n votre choix est d'eliminer un membre:\n");
    break;
    default: printf("Mauvais choix, reessayer:\n\n");
    break;
    }
    break;
    //--------------------------------------------------------------------------------
    //CASE EMPRUNTE
    case 'C' :printf("\n votre choix est emprunt:\n");
    char choixE;
    printf(" |----------------------");
    printf("\n | a.Ajouter un membre\n");
    printf(" |----------------------\n");
    printf(" | b.Afficher un membre\n");
    printf(" |----------------------");
    printf("\n | c.Rechercher un membre\n");
    printf(" |----------------------");
    printf("\n | d.Modifier un membre\n");
    printf(" |----------------------");
    printf("\n | e.Eliminer un membre\n");
    printf(" |----------------------");
    printf("\n\n |----------------------\n");
    printf(" | Faites votre choix!");
    printf("\n |----------------------");
    printf("\n | Lettre : ");
    scanf("%s",&choixE);

    switch(choixE)
    {
    case 'a' :printf("\n Votre choix est de faire un emprunt!!!\n\n");
    printf("\n Combien de membre voulez-vous enrgistrer?\n");
    printf("\n Nombre: ");
    scanf("%d",&n);

    FILE *EMPRUNT=NULL;
    EMPRUNT=fopen("C:/Users/PhiserDie_@Phita/Desktop/projet final C/projet final/emprunt.txt","a+");

    for(i=1; i<=n; i++)
    {
    printf("\n");
    printf("\n Entrer 'Nom d'emprunteur' :");
    scanf("%s",nom_E);
    printf("\n Entrer 'Prenom d'emprunteur' :");
    scanf("%s",prenom_E);
    printf("\n Entrer 'Sexe d'emprunteur' :");
    scanf("%s",sexe_E);
    printf("\n Entrer 'Code d'emprunteur' :");
    scanf("%s",code_E);

    fprintf(EMPRUNT,"\n\n Fiche technique d'emprunteur!!!");
    fprintf(EMPRUNT,"\n Nom emprunteur :%s",nom_E);
    fprintf(EMPRUNT,"\n Prenom emprunteur:%s",prenom_E);
    fprintf(EMPRUNT,"\n Sexe emprunteur :%s",sexe_E);
    fprintf(EMPRUNT,"\n Code emprunteur :%s",code_E);
    }
    fclose(EMPRUNT);
    break;

    case 'b' :printf("\n Votre choix est d'afficher membre:\n");
    break;

    case 'c' :printf("\n votre choix est de rechercher un membre:\n");
    break;

    case 'd' :printf("\n votre choix est de modifier un membre :\n");
    break;

    case 'e' :printf("\n votre choix est d'eliminer un membre:\n");
    break;
    default: printf("Mauvais choix, reessayer:\n\n");
    break;
    }
    break;
    //--------------------------------------------------------------------------------
    break;
    default: printf("Mauvais choix, reessayer:\n\n");
    }

    printf("\n presser 0 pour continuer et q pour quitter:");
    fflush(stdin);
    repond=toupper(getchar());
    }
    while(repond=='0');

    return 0;
    }
    0
  4. Christy SB Messages postés 4 Statut Membre
     
    le travail consiste a realiser un programme capable de gerer une bibliotheque contenant 5 rayons de livres. les lecteurs selon leurs ages auront droit a certains rayons. Le code du lecteur doit etre forme a partir des deux premieres lettres de son nom, des deux premieres de son prenom, des deux premiers chiffres de son annee de naissance et d'un nombre choisi de maniere alleatoire.
    0