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

  1. #1
    Nouveau membre du Club
    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
    Points : 38
    Points
    38
    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 régulier
    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
    Points : 107
    Points
    107
    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
    Nouveau membre du Club
    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
    Points : 38
    Points
    38
    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
    Nouveau membre du Club
    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
    Points : 38
    Points
    38
    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 actif 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
    Points : 222
    Points
    222
    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 éprouvé
    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
    Points : 917
    Points
    917
    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

  7. #7
    Membre éclairé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2010
    Messages
    434
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Janvier 2010
    Messages : 434
    Points : 654
    Points
    654
    Par défaut
    strcmp renvoie 0 si les chaines sont égales.
    si tu met un sur un valeur est vrai si la valeur n'est pas 0.
    Donc quand c'est bon ça passe pas

    donc tu fais ça
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    if (strcmp() == 0)
    ou

    bonne journée

  8. #8
    Nouveau membre du Club
    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
    Points : 38
    Points
    38
    Par défaut
    Pour être plus précis sur mon problème,

    en gros en tant normale quand j'utilise la fonction InpOutFile() le terminale me demande un nom pour mon fichier d'entrée et un pour celui de sortie.

    Or, le problème lorsque je l'insére dans mon menu a choix avec les strcmp c'est qu'il me demande :

    NomDuFichierEntree:NomDuFichierSortie

    Je ne sais pas pourquoi mais il saute le nom du fichier d'entré, et forcément je peux écrire un nom de fichier, mais le programme buguera

  9. #9
    Membre éclairé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2010
    Messages
    434
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Janvier 2010
    Messages : 434
    Points : 654
    Points
    654
    Par défaut
    Pour la taille du buffer dans fgets essaye ça plutôt TAILLE_MAX c'est un peu plus propre que faire un sizeof et à la place de stdin met 0 on sait jamais

  10. #10
    Nouveau membre du Club
    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
    Points : 38
    Points
    38
    Par défaut
    J'ai corrigé, mais toujours le même problème argh

    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
     
    #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 ...");
    */	
            if(strcmp(choix,"-i")==0)
    	{
    	InpOutFile(&Im);
    	fflush(stdin);
     
    	}
     
     /*       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(0);// 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, TAILLE_MAX);
     
        pictureI= fopen(Im1->InpName,"rb");
        		if(pictureI== NULL)
        		perror(Im1->InpName);
     
            printf("dest : ");
            saisir_chaine(Im1->OutName, TAILLE_MAX);
     
            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;
    }

  11. #11
    Membre éclairé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2010
    Messages
    434
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Janvier 2010
    Messages : 434
    Points : 654
    Points
    654
    Par défaut
    fait un read à la place du fgets

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    *
    read(0, lpBuffer, buff_size)

  12. #12
    Nouveau membre du Club
    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
    Points : 38
    Points
    38
    Par défaut
    C'est bon j'ai trouvé le problème c'est ma fonction saisirchaine()

    Par contre j'aurais une dernière question, est ce qu'il est possible dans une structure d'avoir

    Car quand je teste ça ne fonctionne pas et le problème c'est que ça ne m'optimise pas la taille du tableaux

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    typedef struct{
    	 char InpName[TAILLE_MAX];
    	 char OutName[TAILLE_MAX];
    	 int cpt;
    	char tabImage[cpt];
    }Image;

  13. #13
    Membre éclairé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2010
    Messages
    434
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Janvier 2010
    Messages : 434
    Points : 654
    Points
    654
    Par défaut
    d'avoir quoi?

  14. #14
    Nouveau membre du Club
    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
    Points : 38
    Points
    38
    Par défaut
    D'avoir ça

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    typedef struct{
    	 char InpName[TAILLE_MAX];
    	 char OutName[TAILLE_MAX];
    	 int cpt;
    	char tabImage[cpt];
    }Image;
    Plutôt que ça
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    typedef struct{
    	 char InpName[TAILLE_MAX];
    	 char OutName[TAILLE_MAX];
    	 int cpt;
    	char tabImage[2000];
    }Image;
    Car si je mes cpt à la place de 2000, il m'affiche erreur

  15. #15
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 369
    Points : 41 519
    Points
    41 519
    Par défaut
    C'est compliqué, mais possible, avec un usage judicieux de l'allocation dynamique:

    Code C : 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
    #include <stddef.h>
    #include <stdlib.h>
     
    typedef struct{
    	char InpName[TAILLE_MAX];
    	char OutName[TAILLE_MAX];
    	int cpt;
    	char tabImage[]; //Ou tabImage[0] ou tabImage[1] selon l'âge de ton compilo
    } Image;
     
    Image* AllocImage(int cpt)
    {
    	/*Taille à allouer: taille_jusqu_au_tableau + taille_du_tableau*/
    	size_t taille = offsetof(Image, tabImage) + cpt*sizeof(char);
    	Image* ret = calloc(taille, 1);
    	if(ret != NULL)
    		ret->cpt = cpt;
    	return ret;
    }
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

  16. #16
    Nouveau membre du Club
    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
    Points : 38
    Points
    38
    Par défaut
    Si j'ai bien compris pour utiliser cette fonction, il faut la mettre dans la structure et mettre ret dans tabImage[ret] ?

    Parce que j'ai un peu de mal à comprendre la fin de la fonction et aussi la fonction de structure.

  17. #17
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 369
    Points : 41 519
    Points
    41 519
    Par défaut
    C'est une fonction qui alloue un espace suffisant pour:
    • Les champs "normaux" de la structure
    • Le tableau avec de cpt caractères.

    Et retourne un pointeur vers celui-ci, avec en prime cpt réglé.
    Tu peux maintenant utiliser le pointeur de structure normalement:
    Code C : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    Image* monImage = AllocImage(42);
    Image->tabImage[0] = blabla;
    ...
    Image->tabImage[41] = blabla;
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

  18. #18
    Membre actif
    Avatar de EtherOS
    Homme Profil pro
    Etudiant Polytechnicien
    Inscrit en
    Juillet 2012
    Messages
    58
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Cameroun

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

    Informations forums :
    Inscription : Juillet 2012
    Messages : 58
    Points : 233
    Points
    233
    Par défaut Ma Proposition
    Salut!!!

    Pour éviter de s'embrouiller avec les strcmp tu pourrais par exemple utiliser la librairie getopt.h pour gérer les options en ligne de commande je crois que ça te facilitera plus la tâche(en fait cela est conçu pour ça).
    Cordialement!!!!

  19. #19
    Membre éclairé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2010
    Messages
    434
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Janvier 2010
    Messages : 434
    Points : 654
    Points
    654
    Par défaut
    Non il ne peut pas ce n'est pas ligne de commande mais entrée clavier qu'il récupère les options.

    Ensuite tu dois faire un char* tabImage; et utiliser malloc.

    Mais si tu ne maîtrise pas ça je te conseil de revoir les bases soit les pointeurs avec allocation dynamique

  20. #20
    Membre actif
    Avatar de EtherOS
    Homme Profil pro
    Etudiant Polytechnicien
    Inscrit en
    Juillet 2012
    Messages
    58
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Cameroun

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

    Informations forums :
    Inscription : Juillet 2012
    Messages : 58
    Points : 233
    Points
    233
    Par défaut
    Merci , je n'avais pas bien compris le problème posé.

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