IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C Discussion :

Optimisation programme en C


Sujet :

C

Mode arborescent

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2011
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2011
    Messages : 4
    Par défaut Optimisation programme en C
    bonjour,
    alors voila, je viens sur ce forum parce que c'est le dernier recours que j'ai.
    mon problème :
    j'ai ces instructions en C que je suis obligé d'optimiser pour un projet, et franchement je n'y arrive pas !!!
    si quelqu'un pouvais m'aider s'il vous plait.
    merci

    nb: j'ai joint mon code zipé à ce message.

    Applications.c (j'ai le menu du pgm à l'intérieur)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    #include <stdio.h>
    #include <stdlib.h>
    #include <conio.h>
    #include <conio.c>
    #include "applications.h"
     
     
    //////////////////////////////////////
    //
    //////////////////////////////////////
     
    oeuvre Oeuvre_precieuse(){
       oeuvre oeuv_max={"","",0,0};
       oeuvre temp;
       FILE* fichier = NULL;
       fichier = fopen("oeuvre.txt", "r");
     
       if (fichier != NULL)
       {
            while (!feof(fichier))
            {
                fscanf(fichier, "%s %s %d %d", temp.nom, temp.art, &temp.val, &temp.pret);
                if (oeuv_max.val < temp.val)
                {
                    oeuv_max=temp;
                }
            }
           fclose(fichier);
       }
       else printf("Probleme d'ouverture du fichier !");
     
       return oeuv_max;
    }
     
     
    ///////////////////////////////////////
    //
    ///////////////////////////////////////
     
    void Info_oeuvre_precieuse()
    {
        printf("///////////////////////////////////////////////\n");
        printf("// Données concernant une oeuvre précieuse : //\n");
        printf("///////////////////////////////////////////////\n\n");
        Info_oeuvre_param(Oeuvre_precieuse());
    }
     
     
    /////////////////////////////////////////
    //  Procédure affichage oeuvre prêté   //
    /////////////////////////////////////////
     
    void Oeuvre_sorties(){
       oeuvre oeuv_pala={"","",0,0};
       int i=0;
       FILE* fichier = NULL;
       fichier = fopen("oeuvre.txt", "r");
       if (fichier != NULL)
       {
            printf("///////////////////////////\n");
            printf("//   Oeuvres sorties :   //\n");
            printf("///////////////////////////\n\n");
            while (!feof(fichier))
            {
                fscanf(fichier, "%s %s %d %d", oeuv_pala.nom, oeuv_pala.art, &oeuv_pala.val, &oeuv_pala.pret);
                if (oeuv_pala.pret == 1)
                {
                Info_oeuvre_param(oeuv_pala);
                i++;
                }
            }
           fclose(fichier);
           if (i==0)
           {
               printf("Il n'y a aucune oeuvre pretee !\n\n");
           }
       }
       else printf("Probleme d'ouverture du fichier !");
    }
     
     
    //////////////////////////////////////////
    //  SUPPRESSION DE TOUTES LES OEUVRES   //
    //////////////////////////////////////////
     
    void Detruire_collection()
    {
      char rep[2]="";
      FILE* fichier = NULL;
      fichier = fopen("oeuvre.txt", "r");
      if (fichier != NULL)
      {
           printf("--------------------------------\n");
           printf("| Destruction de la collection |\n");
           printf("--------------------------------\n\n");
           printf("Voulez-vous vrament detruire la collection ? (Y/N) : ");
           scanf("%s", rep);
           printf("\n");
           if ((strcmp(rep, "y")==0)||strcmp(rep, "Y")==0)
           {
                           fclose(fichier);
                           remove("oeuvre.txt");
                           FILE* fichier2 = NULL;
                           fichier2 = fopen("oeuvre.txt", "w");
                           fclose(fichier2);
     
                           printf("La collection est bien detruite.\n\n");
           }
      }
      else printf("Erreur d'ouverture de fichier.");
    }
     
     
    ////////////////////////////////////////
    //           MENU PRINCIPAL           //
    ////////////////////////////////////////
     
    int menu()
    {
       int choix=100; // initialisation à n'importe quel entier non inclus dans [0,12]
       while (choix < 0 || choix > 12)
       {
        printf("   M E N U :\n");
        printf("-------------\n\n");
        printf("  OPERATIONS DE BASE :\n\n");
        printf("    1 : Initialisation collection\n");
        printf("    2 : Valeur oeuvre\n");
        printf("    3 : Artiste oeuvre\n");
        printf("    4 : Nom oeuvre\n");
        printf("    5 : Oeuvre pretee\n");
        printf("    6 : Info oeuvre\n\n");
        printf("  OPERATIONS DE HAUT-NIVEAU :\n\n");
        printf("    7 : Ajout oeuvre\n");
        printf("    8 : Suppression oeuvre\n");
        printf("    9 : Liste oeuvre\n\n");
        printf("  APPLICATIONS :\n\n");
        printf("    10 : Info oeuvre precieuse\n");
        printf("    11 : Oeuvres sorties\n");
        printf("    12 : Detruire collection\n\n");
        textcolor(RED);
        cprintf("    13 : Quitter\n\n");
        textcolor(
        printf("Entrer votre choix ? ");
        scanf("%d", &choix);
       }
       return choix;
    }
    fonctions.c :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    #include <stdio.h>
    #include <stdlib.h>
    #include "fonctions.h"
     
     
    /////////////////////////////////////////////////
    //             Ajouter une oeuvre              //
    /////////////////////////////////////////////////
     
    void Ajout_oeuvre ()
    {
        oeuvre euvr={"", "", 0, 0};
     
        FILE* fichier = NULL;
        fichier = fopen("oeuvre.txt", "a");
     
        if (fichier != NULL)
        {
            printf("////////////////////////\n");
            printf("// Ajout d'une oeuvre //\n");
            printf("////////////////////////\n\n");
     
            printf("Entrer le nom de l'oeuvre : ");
            scanf("%s", euvr.nom);
            fprintf(fichier, "\n%s", euvr.nom);
     
            printf("Entrer le nom de l'artiste : ");
            scanf("%s", euvr.art);
            fprintf(fichier, " %s", euvr.art);
     
            printf("Entrer la valeur de l'oeuvre : ");
            scanf("%d", &euvr.val);
            fprintf(fichier, " %d", euvr.val);
     
            printf("Entrer 1 si l'oeuvre est pretee ou 0 si elle est disponible : ");
            scanf("%d", &euvr.pret);
            fprintf(fichier, " %d", euvr.pret);
            printf("\n");
     
            fclose(fichier);
     
            printf("L'oeuvre a bien ete ajoutee.\n\n");
        }
        else
        {
            printf("Probleme d'ouverture du fichier !");
        }
    }
     
     
    /////////////////////////////////////////////////
    //               Liste d'oeuvres               //
    /////////////////////////////////////////////////
     
    void Liste_oeuvre ()
    {
        oeuvre euvr={"", "", 0, 0};
     
        FILE* fichier = NULL;
        fichier = fopen("oeuvre.txt", "r");
     
        if (fichier != NULL)
        {
            printf("///////////////////////\n");
            printf("// Liste des oeuvres //\n");
            printf("///////////////////////n\n");
     
            while (!feof(fichier))
            {
                fscanf(fichier, "%s %s %d %d", euvr.nom, euvr.art, &euvr.val, &euvr.pret);
                printf("Nom de l'oeuvre : %s\n", euvr.nom);
                printf("Artiste de l'oeuvre : %s\n", euvr.art);
                printf("Valeur de l'oeuvre : %d\n", euvr.val);
     
                if (euvr.pret==0)
                {
                    printf("l'oeuvre est disponible\n\n");
                }
                else
                {
                    printf("l'oeuvre est pretee\n\n");
                }
            }
        }
        else
        {
            printf("Probleme d'ouverture du fichier !");
        }
    }
     
     
    /////////////////////////////////////////////////
    //                 Suppression                 //
    /////////////////////////////////////////////////
     
    void Sup_oeuvre()
    {
        oeuvre euvr={"", "", 0, 0};
        int nbligne_copie=0;
        int nbligne_lu=0;
        char nom_rech[20]={""};
        FILE* fichier = NULL;
        fichier = fopen("oeuvre.txt", "r");
        if (fichier != NULL)
        {
            FILE* fichier_tmp = NULL;
            fichier_tmp = fopen("oeuvre_modif.txt", "w");
     
            if (fichier_tmp != NULL)
            {
                printf("//////////////////////////////\n");
                printf("// Suppression d'une oeuvre //\n");
                printf("//////////////////////////////\n\n");
                printf("Entrer le nom de l'oeuvre : ");
                scanf("%s", nom_rech);
                while (!feof(fichier))
                {
                    fscanf(fichier, "%s %s %d %d", euvr.nom, euvr.art, &euvr.val, &euvr.pret);
     
                    if (strcmp(euvr.nom, nom_rech)!=0)
                    {
                        fprintf(fichier_tmp, "\n%s %s %d %d", euvr.nom, euvr.art, euvr.val, euvr.pret);
                        nbligne_copie++;
                    }
                    nbligne_lu++;
                }
                fclose(fichier);
                fclose(fichier_tmp);
     
                if (nbligne_copie!=nbligne_lu)
                {
                    printf("\nL'oeuvre a bien ete supprimee !\n\n");
     
                    remove("oeuvre.txt");
                    rename("oeuvre_modif.txt", "oeuvre.txt");
                }
                else
                {
                    printf("\nL'oeuvre n'est pas referencee !\n\n");
                    remove("oeuvre_modif.txt");
                }
            }
            else
            {
                printf("Probleme d'ouverture du fichier temporaire !");
            }
        }
        else
        {
            printf("Probleme d'ouverture du fichier source !");
        }
    }

    Opérations_de_base.c :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    #include <stdio.h>
    #include <stdlib.h>
    #include "operations_de_base.h"
     
     
    ///////////////////////////////////
    //
    ///////////////////////////////////
     
    void Init_collection()
    {
        oeuvre o={"", "", 0, 0};
     
        FILE *fichier=NULL;
        fichier=fopen("oeuvre.txt", "w");
     
        if (fichier != NULL)
        {
            printf("//////////////////////////////////////////////\n");
            printf("// Initialisation de la collection d'oeuvre //\n");
            printf("//////////////////////////////////////////////\n\n");
     
            printf("Entrer le nom de l'oeuvre : ");
            scanf("%s", o.nom);
            fprintf(fichier, "%s", o.nom);
     
            printf("Entrer le nom de l'artiste : ");
            scanf(" %s", o.art);
            fprintf(fichier, " %s", o.art);
     
            printf("Entrer la valeur de l'oeuvre : ");
            scanf(" %d", &o.val);
            fprintf(fichier, " %d", o.val);
     
            printf("Entrer 1 si l'oeuvre est pretee ou 0 si elle est disponible : ");
            scanf(" %d", &o.pret);
            fprintf(fichier, " %d", o.pret);
            printf("\n");
     
            fclose(fichier);
     
            printf("La collection est initialisee.\n\n");
        }
        else
        {
            printf("Erreur d'ouverture du fichier !");
        }
    }
     
     
    ///////////////////////////////////
    //
    ///////////////////////////////////
     
    void Valeur_oeuvre()
    {
        oeuvre o={"", "", 0, 0};
        int trouve=0;
        char nom_rech[20]={""};
     
        FILE* fichier = NULL;
        fichier = fopen("oeuvre.txt", "r");
     
        if (fichier != NULL)
        {
            printf("-----------------------\n");
            printf("| Valeur d'une oeuvre |\n");
            printf("-----------------------\n\n");
     
            printf("Entrer le nom de l'oeuvre : ");
            scanf("%s", nom_rech);
     
            while (!feof(fichier))
            {
            fscanf(fichier, "%s %s %d %d", o.nom, o.art, &o.val, &o.pret);
     
            if (strcmp(o.nom, nom_rech)==0)
                {
                printf("\nValeur de l'oeuvre : %d Euros\n\n", o.val);
                trouve=1;
                }
            }
     
            if (trouve==0)
            {
                printf("\nCette oeuvre n'est pas referencee !\n\n");
            }
            fclose(fichier);
        }
        else
        {
            printf("Probleme d'ouverture du fichier !");
        }
    }
     
     
    ///////////////////////////////////
    //
    ///////////////////////////////////
     
    void Nom_oeuvre()
    {
        oeuvre o={"", "", 0, 0};
        int trouve=0;
        char art_rech[20]={""};
     
        FILE* fichier = NULL;
        fichier = fopen("oeuvre.txt", "r");
     
        if (fichier != NULL)
        {
            printf("--------------------\n");
            printf("| Nom d'une oeuvre |\n");
            printf("--------------------\n\n");
     
            printf("Entrer le nom de l'artiste : ");
            scanf("%s", art_rech);
     
            while (!feof(fichier))
            {
            fscanf(fichier, "%s %s %d %d", o.nom, o.art, &o.val, &o.pret);
     
            if (strcmp(o.art, art_rech)==0)
                {
                printf("\nNom de l'oeuvre : %s\n\n", o.nom);
                trouve=1;
                }
            }
     
            if (trouve==0)
            {
                printf("\nCette artiste n'est pas referencee !\n\n");
            }
            fclose(fichier);
        }
        else
        {
            printf("Probleme d'ouverture du fichier !");
        }
    }
     
     
    //////////////////////////////////////
    //
    //////////////////////////////////////
     
    void Artiste_oeuvre()
    {
        oeuvre o={"", "", 0, 0};
        int trouve=0;
        char nom_rech[20]={""};
     
        FILE* fichier = NULL;
        fichier = fopen("oeuvre.txt", "r");
     
        if (fichier != NULL)
        {
            printf("--------------------\n");
            printf("| Nom d'un artiste |\n");
            printf("--------------------\n\n");
     
            printf("Entrer le nom de l'oeuvre : ");
            scanf("%s", nom_rech);
     
            while (!feof(fichier))
            {
            fscanf(fichier, "%s %s %d %d", o.nom, o.art, &o.val, &o.pret);
     
            if (strcmp(o.nom, nom_rech)==0)
                {
                printf("\nArtiste qui a realise l'oeuvre : %s\n\n", o.art);
                trouve=1;
                }
            }
     
            if (trouve==0)
            {
                printf("\nCette oeuvre n'est pas referencee !\n\n");
            }
            fclose(fichier);
        }
        else
        {
            printf("Probleme d'ouverture du fichier !");
        }
    }
     
    void Pret_oeuvre()
    {
        oeuvre o={"", "", 0, 0};
        int trouve=0;
        char nom_rech[20]={""};
     
        FILE* fichier = NULL;
        fichier = fopen("oeuvre.txt", "r");
     
        if (fichier != NULL)
        {
            printf("---------------------\n");
            printf("| Pret d'une oeuvre |\n");
            printf("---------------------\n\n");
     
            printf("Entrer le nom de l'oeuvre : ");
            scanf("%s", nom_rech);
     
            while (!feof(fichier))
            {
                fscanf(fichier, "%s %s %d %d", o.nom, o.art, &o.val, &o.pret);
     
                if (strcmp(o.nom, nom_rech)==0)
                {
                    if (o.pret==0)
                    {
                    printf("\nl'oeuvre est disponible\n\n");
                    }
                    else
                    {
                    printf("\nl'oeuvre est pretee\n\n");
                    }
                    trouve=1;
                }
            }
     
            if (trouve==0)
            {
                printf("\nCette oeuvre n'est pas referencee !\n\n");
            }
            fclose(fichier);
        }
        else
        {
            printf("Probleme d'ouverture du fichier !");
        }
    }
     
    void Info_oeuvre()
    {
        oeuvre o={"", "", 0, 0};
        int trouve=0;
        char nom_rech[20]={""};
     
        FILE* fichier = NULL;
        fichier = fopen("oeuvre.txt", "r");
     
        if (fichier != NULL)
        {
            printf("-----------------------------\n");
            printf("| Informations d'une oeuvre |\n");
            printf("-----------------------------\n\n");
     
            printf("Entrer le nom de l'oeuvre : ");
            scanf("%s", nom_rech);
     
            while (!feof(fichier))
            {
            fscanf(fichier, "%s %s %d %d", o.nom, o.art, &o.val, &o.pret);
     
            if (strcmp(o.nom, nom_rech)==0)
                {
                    printf("\nNom de l'oeuvre : %s\n", o.nom);
                    printf("Artiste qui a realise l'oeuvre : %s\n", o.art);
                    printf("Valeur de l'oeuvre : %d Euros\n", o.val);
     
                    if (o.pret==0)
                    {
                        printf("l'oeuvre est disponible\n\n");
                    }
                    else
                    {
                        printf("l'oeuvre est pretee\n\n");
                    }
                    trouve=1;
                }
            }
     
            if (trouve==0)
            {
                printf("\nCette oeuvre n'est pas referencee !\n\n");
            }
            fclose(fichier);
        }
        else
        {
            printf("Probleme d'ouverture du fichier !");
        }
    }
     
    void Info_oeuvre_param(oeuvre o)
    {
        printf("Nom de l'oeuvre : %s\n", o.nom);
        printf("Artiste qui a realise l'oeuvre : %s\n", o.art);
        printf("Valeur de l'oeuvre : %d\n", o.val);
     
        if (o.pret==0)
        {
            printf("l'oeuvre est disponible\n\n");
        }
        else
        {
            printf("l'oeuvre est pretee\n\n");
        }
    }

    type_oeuvre.h
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    #include <stdio.h>
    #include <stdlib.h>
     
    struct oeuvre
    {
        char nom[20];
        char art[20];
        int val;
        int pret;
    };
    typedef struct oeuvre oeuvre;
    Fichiers attachés Fichiers attachés

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [IML] Optimiser programme avec IML
    Par Billou265 dans le forum SAS IML
    Réponses: 3
    Dernier message: 02/09/2011, 16h21
  2. [Débutant] tableau pour optimiser programme
    Par membreComplexe12 dans le forum MATLAB
    Réponses: 2
    Dernier message: 15/03/2010, 10h03
  3. Optimisation programmation Interface
    Par christophe_halgand dans le forum Interfaces Graphiques
    Réponses: 1
    Dernier message: 28/02/2008, 18h49
  4. Optimisation programme ::
    Par scolopendra dans le forum Langage
    Réponses: 5
    Dernier message: 16/04/2007, 17h53
  5. Optimiser programme (D7)
    Par mario9 dans le forum Delphi
    Réponses: 2
    Dernier message: 18/08/2006, 17h36

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo