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 :

Choix de fonctions


Sujet :

C

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2013
    Messages
    70
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juillet 2013
    Messages : 70
    Par défaut Choix de fonctions
    Bonjour,

    Je suis en train de réaliser un programme qui permet de faire
    différentes action sur une image, les fonctions sont déjà testé et fonctionnelle.
    Mais je ne sais pas pourquoi, lorsque je teste il ne rentre jamais dans le strcmp que je souhaite.

    ex: je tape "-i"il m'affiche "need help ?",voire ça m'est déjà arriver qu'il fasse toutes les fonctions.

    Je vous remercies d'avance !

    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
    #include <stdio.h>
    #include <stdlib.h>
    #include<string.h>
     
    //#include "Structure.h"
    //#include "Prototype.h"
    //#include "Function.h"
     
    int main()
    {
        char choix[6]="";
     
        for(;;)
        {
            printf("PANORAMA(7)\n\n");
            printf("NAME\n");
            printf("  panorama - automatically create panoramas \n\n");
            printf("SYNOPSIS\n");
            printf("  panorama [OPTION]...\n\n");
            printf("DESCRIPTION\n");
            printf("  Image manipulation helper to create panoram\n\n");
            printf("USAGE \n");
            printf("  Usage : panorama [OPTION...]\n\n");
            printf("  Help options\n");
            printf("   -?, --help      Shows this help message\n");
            printf("  General Options\n");
            printf("   -g              Convert the input file(s) to grayscale\n");
            printf("   -h              Extract the histogram from the input file(s)\n");
            printf("   -e              Erode the input file(s)\n");
            printf("   -d              Dilate the input file(s)\n");
            printf("   -b threshold    Render a black-white image using the giving threshold \n");
            printf("   -c file         Apply a convolution on the input file(s) using the \n given file as the convolution matrix\n");
            printf("   -p              Render the panorama from the input file(s)\n");
            printf(" Working on single file\n");
            printf("   -i file         Define the input file\n");
            printf("   -o file         Define the output file\n");
            printf(" Using multiple files\n");
            printf("   -li file1,file2,...,filen   Define a set of files as the input\n");
            printf("   -lo file1,file2,...,filen   Define a set of files as the output\n");
            printf("   -exit           Exit\n");
     
            scanf("%s",choix);
            printf("%s",choix);
     
            if(strcmp(choix,"-?"))
                printf("need help ?");
     
            else if(strcmp(choix,"--help"))
                printf("need mega help ?");
     
            else if(strcmp(choix,"-g"))
                printf("work in progress ...");
     
            else if(strcmp(choix,"-h"))
                printf("work in progress ...");
     
            else if(strcmp(choix,"-e"))
                printf("work in progress ...");
     
            else if(strcmp(choix,"-d"))
                printf("work in progress ...");
     
            else if(strcmp(choix,"-b"))
                printf("work in progress ...");
     
            else if(strcmp(choix,"-c"))
                printf("work in progress ...");
     
            else if(strcmp(choix,"-p"))
                printf("work in progress ...");
     
            else if(strcmp(choix,"-i"))
            {
                /*InpOutFile(&Im);
                cptChar(&Im);
                StockMemory(&Im);*/
            }
     
            else if(strcmp(choix,"-o"))
            {
                //CopyFile(&Im);
                printf("ok11");
            }
     
            else if(strcmp(choix,"-li"))
                printf("work in progress ...");
     
            else if(strcmp(choix,"-lo"))
                printf("work in progress ...");
     
            else if(strcmp(choix,"-exit"))
                exit (0);
     
        }
     
     
    }

  2. #2
    Membre actif
    Profil pro
    Ingénieur
    Inscrit en
    Avril 2013
    Messages
    77
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur

    Informations forums :
    Inscription : Avril 2013
    Messages : 77
    Par défaut
    Bonjuor,

    Tu trouveras la réponse dans ce que te renvoies la fonction strcmp:
    ici

    Quand les deux chaînes sont égales, la valeur retournée est 0.

  3. #3
    Membre confirmé
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2013
    Messages
    70
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juillet 2013
    Messages : 70
    Par défaut
    Je me suis trompé dans ce que je voulais exactement demander, en
    fait mon problème est que toutes mes fonctions quand je les teste ensembles elles fonctionnent, mais dés que j'en mes une dans le programme a choix, ça ne marche plus du tout.

    C'est à dire que la par exemple j'ai mis une fonction qui ouvre un fichier dont on donne le nom et j'en ai une seconde qui créer un fichier de sortie en me demandant une fois de plus un nom à ce fichier.

    Lorsque je teste, il y'a un gros bug il m'affiche "input:output:" (alors que normalement ça marche très bien !)

    J'avoue ne pas comprendre du tout.

    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
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
     
    /********Constant**************/
    #define TAILLE_MAX 20
     
    /*******Struct_1***************/
    typedef struct
    {
        char InpName[TAILLE_MAX];
        char OutName[TAILLE_MAX];
        int cpt;
        char tabImage[2000];
    } Image;
     
    /*********Prototypes***********/
    void InpOutFile(Image *Im1);
    char * saisir_chaine(char * lpBuffer, int buf_size);
    void cptChar(Image *Im2);
    void CopyFile(Image *Im3);
    void StockMemory(Image *Im3);
     
     
    int main()
    {
        char choix[6]="";
     
        Image Im;
     
        for(;;)
        {
     
            printf("PANORAMA(7)\n\n");
            printf("NAME\n");
            printf("  panorama - automatically create panoramas \n\n");
            printf("SYNOPSIS\n");
            printf("  panorama [OPTION]...\n\n");
            printf("DESCRIPTION\n");
            printf("  Image manipulation helper to create panoram\n\n");
            printf("USAGE \n");
            printf("  Usage : panorama [OPTION...]\n\n");
            printf("  Help options\n");
            printf("   -?, --help      Shows this help message\n");
            printf("  General Options\n");
            printf("   -g              Convert the input file(s) to grayscale\n");
            printf("   -h              Extract the histogram from the input file(s)\n");
            printf("   -e              Erode the input file(s)\n");
            printf("   -d              Dilate the input file(s)\n");
            printf("   -b threshold    Render a black-white image using the giving threshold \n");
            printf("   -c file         Apply a convolution on the input file(s) using the \n given file as the convolution matrix\n");
            printf("   -p              Render the panorama from the input file(s)\n");
            printf(" Working on single file\n");
            printf("   -i file         Define the input file\n");
            printf("   -o file         Define the output file\n");
            printf(" Using multiple files\n");
            printf("   -li file1,file2,...,filen   Define a set of files as the input\n");
            printf("   -lo file1,file2,...,filen   Define a set of files as the output\n");
            printf("   -exit           Exit\n");
     
            scanf("%s",choix);
     
            if(strcmp(choix,"-?") ==0)
                printf("need help ?");
     
            else if(strcmp(choix,"--help")==0)
                printf("need mega help ?");
     
            else if(strcmp(choix,"-g")==0)
                printf("work in progress ...");
     
            else if(strcmp(choix,"-h")==0)
                printf("work in progress ...");
     
            else if(strcmp(choix,"-e")==0)
                printf("work in progress ...");
     
            else if(strcmp(choix,"-d")==0)
                printf("work in progress ...");
     
            else if(strcmp(choix,"-b")==0)
                printf("work in progress ...");
     
            else if(strcmp(choix,"-c")==0)
                printf("work in progress ...");
     
            else if(strcmp(choix,"-p")==0)
                printf("work in progress ...");
     
            else if(strcmp(choix,"-i")==0)
            {
                InpOutFile(&Im);
     
            }
     
            else if(strcmp(choix,"-o")==0)
            {
     
            }
     
            else if(strcmp(choix,"-li")==0)
                printf("work in progress ...");
     
            else if(strcmp(choix,"-lo")==0)
                printf("work in progress ...");
     
            else if(strcmp(choix,"-exit")==0)
                exit (0);
     
            fflush(stdin);// On vide le buffer clavier
        }
    }
     
    /******Function***************/
    void InpOutFile(Image *Im1)
    {
     
        FILE *pictureI=NULL;
        FILE *pictureO=NULL;
     
        printf("Ce programme permet de copier un fichier.\n");
        printf("source : ");
        saisir_chaine(Im1->InpName, sizeof(Im1->InpName));
     
        pictureI= fopen(Im1->InpName,"rb");
        if(pictureI== NULL)
            perror(Im1->InpName);
     
        printf("dest : ");
        saisir_chaine(Im1->OutName, sizeof(Im1->OutName));
     
        if (strcmp(Im1->InpName, Im1->OutName) == 0)
            printf("La source ne peut pas etre en meme temps la destination.\n");
        else
        {
            pictureO = fopen(Im1->OutName,"wb");
            if (pictureO == NULL)
                perror(Im1->OutName);
        }
        close(pictureI);
        close(pictureO);
    }
     
    char * saisir_chaine(char * lpBuffer, int buf_size)
    {
        char * ret = fgets(lpBuffer, buf_size, stdin);
     
        if (ret != NULL)
        {
            char * p = strchr(lpBuffer, '\n');
            if (p != NULL)
                *p = '\0';
            else
            {
                int c;
     
                do
                    c = getchar();
                while (c != EOF && c != '\n');
            }
        }
        return ret;
    }

  4. #4
    Membre confirmé
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2013
    Messages
    70
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juillet 2013
    Messages : 70
    Par défaut
    Mes deux fonctions sont très fortement inspiré de cette article
    http://melem.developpez.com/tutoriel...age=cours#LI-E

  5. #5
    Membre expérimenté Avatar de moins1
    Homme Profil pro
    Autre
    Inscrit en
    Février 2013
    Messages
    85
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Autre
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Février 2013
    Messages : 85
    Par défaut
    Ton code est vraiment mal indenté. On sait pas quel "else" appartient à quel "if" entre autre.



    Message des modérateurs : code indenté

  6. #6
    Membre éclairé
    Avatar de EpiTouille
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2009
    Messages
    372
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2009
    Messages : 372
    Par défaut
    Bonjour,

    Pourrait-on avoir une description de l'erreur plus précise, pourquoi pas un log valgrind ansi que les lignes qui boguent ? Sinon, il est très difficile de vous aider,

    merci

Discussions similaires

  1. [Débutant] Choix de fonction à l'intérieur d'une boucle
    Par mdelvaux89 dans le forum MATLAB
    Réponses: 7
    Dernier message: 08/04/2009, 12h01
  2. [Processeur] choix en fonction de mon activité
    Par zooffy dans le forum Composants
    Réponses: 24
    Dernier message: 19/03/2009, 15h37
  3. Réponses: 3
    Dernier message: 13/08/2008, 14h36
  4. Choix de fonction à l'ouverture d'Excel
    Par SKY400 dans le forum Macros et VBA Excel
    Réponses: 1
    Dernier message: 18/05/2007, 10h49
  5. Réponses: 4
    Dernier message: 19/10/2005, 21h34

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