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

GTK+ Discussion :

[GLib]g_print et indentation


Sujet :

GTK+

  1. #1
    Membre du Club
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Septembre 2017
    Messages
    43
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : Bâtiment

    Informations forums :
    Inscription : Septembre 2017
    Messages : 43
    Points : 64
    Points
    64
    Par défaut [GLib]g_print et indentation
    Bonsoir à tous,

    Pour indenter des structures de donné j'utilise:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    g_print("%*s%s\n", 4, "", "<input />");// 4 espaces. output: "    <input />"
    J'aimerai utiliser 1 tabulation au lieu de 4 espaces.

    Dans un vague souvenir, pour obtenir la sortie "####<input />" il m'arrivais d'utiliser une syntaxe du type printf("%#*s\n", 4, "<input />"); mais aujourd'hui sans succès, j'obtient " <input />" et quand je remplace '#' par '\t' j'obtiens % *s
    Quelqu'un vois mon erreur

  2. #2
    Modérateur

    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juin 2009
    Messages
    1 395
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2009
    Messages : 1 395
    Points : 2 002
    Points
    2 002
    Par défaut
    Bonjour,

    cf man 3 printf:

    The field width
    An optional decimal digit string (with nonzero first digit) specifying a minimum field width. If the converted value has fewer characters than the field width, it will be padded with spaces on the
    left (or right, if the left-adjustment flag has been given). Instead of a decimal digit string one may write "*" or "*m$" (for some decimal integer m) to specify that the field width is given in
    the next argument, or in the m-th argument, respectively, which must be of type int. A negative field width is taken as a '-' flag followed by a positive field width. In no case does a nonexistent
    or small field width cause truncation of a field; if the result of a conversion is wider than the field width, the field is expanded to contain the conversion result.
    Donc la technique que tu utilises fonctionne parce que derrière g_printf, printf indente avec des espaces pour forcer la largeur de ton champ. En revanche rien ne dit qu'il peut faire de même avec des tabulations.
    Documentation officielle GTK+ 3:
    GTK en C, GTK en Python

    Tutoriels GTK+ 3:
    GTK en C, GTK en Python

    Tutoriels par l'exemple (platform-demos):
    GTK (tous langages)

  3. #3
    Membre du Club
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Septembre 2017
    Messages
    43
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : Bâtiment

    Informations forums :
    Inscription : Septembre 2017
    Messages : 43
    Points : 64
    Points
    64
    Par défaut
    Bonjour, et merci pour ton aide liberforce

    Je viens de lire le code source de printf de la libc et le verdict est sans appel. le caractères de remplissage est codé en dur : PAD (' ');

    Ca m'agace, je suis persuadé avoir déjà modifier le caractère de remplissage


    PS: En prenant le problème a l’envers, j'ai bricolé ca pour le coup.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
        static char indentation_buffer[] = {'\t', '\t', '\t', '\t', '\t', '\t', '\t', '\t', '\t', '\t', '\t', '\t', '\t'};
        g_print("%.*s%s\n", 1, indentation_buffer, "<input />");// output: "	<input />"

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

Discussions similaires

  1. XSLT -> HTML : formatage : indentation et retour a la lig
    Par jiib75 dans le forum XSL/XSLT/XPATH
    Réponses: 2
    Dernier message: 01/05/2004, 11h11
  2. [mise en page] pour bien indenter son code
    Par bihorece dans le forum C++Builder
    Réponses: 4
    Dernier message: 06/08/2003, 16h14
  3. indentation automatique
    Par Boosters dans le forum JBuilder
    Réponses: 3
    Dernier message: 17/07/2003, 16h44
  4. [Source>Format :)] indentation automatik
    Par iubito dans le forum Eclipse Java
    Réponses: 2
    Dernier message: 10/06/2003, 16h37
  5. [indentation]Jbuilder 8
    Par partyboy dans le forum JBuilder
    Réponses: 2
    Dernier message: 26/03/2003, 13h39

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