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 :

Besoin d aide pour decouper un fonction


Sujet :

C

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    165
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2008
    Messages : 165
    Par défaut Besoin d aide pour decouper un fonction
    Bonjour, ci apres le code d une fonction que je vien de realiser... le souci celle ci fait beaucoup de ligne, l ideal serai qu elle n en fasse que 25 , je doit donc la decouper, cependant je bug un peu notamen a cause des pointeurs...
    Merci 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
     
    void            my_printopt(char **str, va_list *ap)
    {
      t_flag        *my_struct;
      int           width;
      int           i;
     
      width = 0;
      i = 0;
      (*str)++;
      my_struct = init();
      if (*(*str) == '-' || *(*str) == '+' || *(*str) == ' ' || *(*str) == '#'
          || *(*str) == '0')
        {
          my_struct->flags = *(*str);
          (*str)++;
        }
      else
        my_struct->flags = '~';
      while (*(*str) >= '0' && *(*str) <= '9')
        {
          width = width * 10 + *(*str) - '0';
          (*str)++;
        }
      if (width)
        my_struct->width = width;
      else
        my_struct->width = -1;
      width = 0;
      if (*(*str) == '.')
        {
          (*str)++;
          if (*(*str) == '*')
            my_struct->precision = -2;
          else
            {
              while (*(*str) >= '0' && *(*str) <= '9')
                {
                  width = width * 10 + *(*str) - '0';
                  (*str)++;
                }
              if (width)
                my_struct->precision = width; 
             else
                my_struct->precision = -1;
            }
        }
      my_struct->list = ap;
      while (op_print[i].opt)
        {
          if (*(*str) == op_print[i].opt)
            {
              op_print[i].fct_p(my_struct);
            }
          i++;
        }
      free(my_struct);
    }
    Ps le for est interdi

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

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

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 395
    Par défaut
    l ideal serai qu elle n en fasse que 25
    PS le for est interdit
    Je crois qu'il va falloir ajouter un tag [ EPITECH ] dans le titre des threads...

    Mais déjà, pourrait-on avoir un code compilable pour mieux t'aider? Je ne connais pas le type t_flag...
    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.

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    165
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2008
    Messages : 165
    Par défaut
    autan pour moi,
    voila le type t_flag
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    typedef struct   s_flag
    {
      char          flags;
      int           width;
      int           precision;
      int           lenght;
      char          specifer;
      va_list       *list;
    }t_flag;
    c'est pour recuperer les options de mon printf

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

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

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 395
    Par défaut
    Il manque aussi la fonction init(), et op_print, qui semble être un tableau global (pas bien!).
    PS: Je suppose que l'opérateur ternaire "?:" vous est interdit aussi?
    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.

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

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

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 395
    Par défaut
    Après avoir remplacé les fonctions qui manquaient par des déclarations bidon, j'obtiens un truc de ce genre:
    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
    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
    #include <stdlib.h>
     
    typedef struct s_flag
    {
    	char flags;
    	int width;
    	int precision;
    	int lenght;
    	char specifer;
    	va_list *list;
    } t_flag;
     
    t_flag *init();
     
    extern struct {
    	void (*fct_p)(t_flag*);
    	char opt;
    } op_print[];
     
    typedef int EPITECH_BOOL;
    #define EPITECH_FALSE 0
    #define EPITECH_TRUE  1
     
    int OperateurTernaire_int(EPITECH_BOOL bCondition, int valeurSiOui, int valeurSiNon)
    {
    	if(bCondition)
    		return valeurSiOui;
    	else
    		return valeurSiNon;
    }
     
    EPITECH_BOOL IsFlag(char c)
    {
    	if(c == '-' || c == '+' || c == ' ' || c == '#' || c == '0')
    		return EPITECH_TRUE;
    	else
    		return EPITECH_FALSE;
    }
     
    void NextChar(char **ppCurrentChar)
    {
    	(*ppCurrentChar)++;
    }
     
    int ParseInt(char **ppCurrentChar)
    {
    	int value = 0;
    	while (**ppCurrentChar >= '0' && **ppCurrentChar <= '9')
    	{
    		value *= 10;
    		value += (**ppCurrentChar - '0');
    		NextChar(ppCurrentChar);
    	}
    	return value;
    }
     
    void FindAndCallPrintFunction(char currentChar, t_flag *pStruct)
    {
    	int i;
     
    	i = 0;
    	while (op_print[i].opt)
    	{
    		if (currentChar == op_print[i].opt)
    		{
    			op_print[i].fct_p(pStruct);
    		}
    		i++;
    	}
    }
     
    void ParseStruct(char **ppCurrentChar, t_flag *pStruct)
    {
    	int width;
    	if (IsFlag(**ppCurrentChar))
    	{
    		pStruct->flags = **ppCurrentChar; /*Est-ce normal qu'on ne puisse stocker qu'un seul flag dans un champ appelé "flags" ?*/
    		NextChar(ppCurrentChar);
    	}
    	else
    		pStruct->flags = '~';
    	width = ParseInt(ppCurrentChar);
    	pStruct->width = OperateurTernaire_int(width!=0, width, -1);
    	if (**ppCurrentChar == '.')
    	{
    		NextChar(ppCurrentChar);
    		if (**ppCurrentChar == '*')
    			pStruct->precision = -2;
    		else
    		{
    			int const precision = ParseInt(ppCurrentChar);
    			pStruct->precision = OperateurTernaire_int(precision!=0, precision, -1);
    		}
    	}
    }
     
    void my_printopt(char **ppCurrentChar, va_list *ap)
    {
    	t_flag *pStruct;
     
    	NextChar(ppCurrentChar); /*sauter le pourcent*/
    	pStruct = init();
    	if(pStruct != NULL)
    	{
    		ParseStruct(ppCurrentChar, pStruct);
    		pStruct->list = ap;
    		FindAndCallPrintFunction(**ppCurrentChar, pStruct);
    		free(pStruct);
    	}
    }
    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.

  6. #6
    Membre confirmé
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    165
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2008
    Messages : 165
    Par défaut
    Je vais teste ceci merci bocoup

Discussions similaires

  1. Besoin d'aide pour créer une fonction
    Par xavxx58 dans le forum Prolog
    Réponses: 13
    Dernier message: 14/09/2008, 13h03
  2. Besoin d'aide pour lancement de fonctions à partir des touches du clavier
    Par narcis60floyjo dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 13/03/2008, 00h08
  3. besoin d'aide pour fonction de conversion de base
    Par babou54 dans le forum Delphi
    Réponses: 12
    Dernier message: 13/01/2007, 21h06
  4. [Mail] besoin d'aide pour la fonction mail
    Par laymounos dans le forum Langage
    Réponses: 5
    Dernier message: 07/06/2006, 21h16
  5. Besoin d'aide pour fonctions OpenSSL..... HELP !!!
    Par aide64 dans le forum Langage
    Réponses: 7
    Dernier message: 12/05/2006, 17h46

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