logo Debian Debian Debian-France Debian-Facile Debian-fr.org Forum-Debian.fr Debian ? Communautés logo inclusivité

Debian-facile

Bienvenue sur Debian-Facile, site d'aide pour les nouveaux utilisateurs de Debian.

Vous n'êtes pas identifié(e).

#2 Re : Scripts, programmes et robots » {C} concatenation a la chaine » 16-02-2020 17:39:57

Clem
Nickel ca marche big_smile

cependant je ne comprends pas cette manipulation:

strcpy(chaine+l, A->justification);
{...]
strcpy(chaine+l++, "\n");

Et la fonction strcpy n'est pas censée écraser le contenu de la chaine receptrice?

#3 Re : Scripts, programmes et robots » {C} concatenation a la chaine » 16-02-2020 11:10:23

Clem
Hop:


char* struct_to_str_un (GSList* G)
{
    p_maille A = g_slist_nth_data(G,0);
    int i = strlen (A->justification);
    char* chaine = malloc(sizeof (char) * (i+1));
    strcpy (chaine, A->justification);
    strcat(chaine, "\n");
    G=g_slist_next(G);

    while (G)
    {
  char *tmp;
  int i,j;
  p_maille A = g_slist_nth_data(G,0);

  j= strlen (chaine);
  i= strlen (A->justification);
  tmp = malloc(sizeof(char)* (j));
 
  strcpy(tmp,chaine);
  free(chaine);

 
  chaine = malloc(sizeof(char) * (i+j+1));
 
  strcpy(chaine,tmp);
  strcat(chaine, A->justification);
  strcat(chaine, "\n");

  free(tmp);

  G=g_slist_next(G);
    }

    return chaine;
}

 

#4 Re : Scripts, programmes et robots » {C} concatenation a la chaine » 16-02-2020 10:40:30

Clem

raleur a écrit :

Que veux-tu obtenir exactement ? Si tu veux la taille d'un tableau de (i+j) caractères,


Oui ç'est ça.


 char* chaine = malloc(sizeof (char) * (i+1));
[...}
tmp = malloc(sizeof(char)* (j));
[...]
chaine = malloc(sizeof(char) * (i+j+1));
 


Là, le compilateur ne me renvoit plus d'erreur.
Je ne suis pas sur d'avoir compris toute la subtilité de la chose...

Par contre a l'execution j'ai le droit à :


realloc(): invalid next size
Abandon
 



L'erreur se situe en dehors de la fonction j'ai l'impresssion:


char *justification = struct_to_str(G);

  printf("justification : %s\n", justification);

  lbl=gtk_label_new("premier \nsecond \ntertiaire \n");
  gtk_label_set_text (GTK_LABEL (lbl), justification);
  gtk_container_add(GTK_CONTAINER(frame), lbl);

 

#5 Re : Scripts, programmes et robots » error: ‘GSList’ {aka ‘struct _GSList’} has no member named ‘A » 15-02-2020 19:10:45

Clem
Je m'auto-répond.
Il siffisait juste d'utiliser la fonction:

gpointer
g_slist_nth_data (GSList *list,
                  guint n);

#6 Re : Scripts, programmes et robots » {C} concatenation a la chaine » 15-02-2020 18:50:01

Clem
Ho, la bourde.
Merci c'est rectifié.


char* chaine = malloc(sizeof (char * (i+1)));
 

etc...

maintenant le compilateur me renvoit des erreurs que je ne comprends pas:


 gcc -W -Werror -Wall -ansi `pkg-config --cflags --libs gtk+-3.0` ~/Code/C/Essai/Essai.c -o ~/Code/C/Essai/Essai -std=c11
/home/clem/Code/C/Essai/Essai.c: In function ‘struct_to_str’:
/home/clem/Code/C/Essai/Essai.c:234:43: error: expected ‘)’ before ‘i’
     char* chaine = malloc(sizeof (char * (i+1)));
                                           ^
                                           )
/home/clem/Code/C/Essai/Essai.c:247:28: error: expected ‘)’ before ‘j’
  tmp = malloc(sizeof(char*(j)));
                            ^
                            )
/home/clem/Code/C/Essai/Essai.c:253:32: error: expected ‘)’ before ‘i’
  chaine = malloc(sizeof(char *(i+j+1)));
                                ^
                                )
/home/clem/Code/C/Essai/Essai.c:242:8: error: variable ‘j’ set but not used [-Werror=unused-but-set-variable]
  int i,j;
        ^
/home/clem/Code/C/Essai/Essai.c:242:6: error: variable ‘i’ set but not used [-Werror=unused-but-set-variable]
  int i,j;
      ^
/home/clem/Code/C/Essai/Essai.c:233:9: error: unused variable ‘i’ [-Werror=unused-variable]
     int i = strlen (A->justification);
         ^
cc1: all warnings being treated as errors

 

#7 Scripts, programmes et robots » {C} concatenation a la chaine » 15-02-2020 04:15:19

Clem
Réponses : 15
Bonjour a tous

Je dois etre miro. J'ai une erreur sur un code tout simple:


char* struct_to_str (GSList* G)
{
    p_maille A = g_slist_nth_data(G,0);
    char* chaine = malloc(sizeof (A->justification+1));
    strcpy (chaine, A->justification);
    strcat(chaine, "\n");
    G=g_slist_next(G);

    while (G)
    {
  char *tmp;
  int i,j;
  p_maille A = g_slist_nth_data(G,0);

  j= strlen (chaine);
  i= strlen (A->justification);
  tmp = malloc(sizeof(chaine));
 
  strcpy(tmp,chaine);
  free(chaine);

 
  chaine = malloc(sizeof(i+j+1));
 
  strcpy(chaine,tmp);
  strcat(chaine, A->justification);
  strcat(chaine, "\n");

  free(tmp);

  G=g_slist_next(G);
    }

    return chaine;
}
 



L'erreur :


free(): invalid size
Abandon
 



Je n'arrive pas a deviner ce qui ne marche pas. Les variables m'ont  l'air correctement allouées.

#8 Re : Scripts, programmes et robots » error: ‘GSList’ {aka ‘struct _GSList’} has no member named ‘A » 31-01-2020 04:35:40

Clem

kao a écrit :

A quel moment tu déclares que B contient une structure de type maille ?
B->maille suggère que tu vas trouver un élément nommé "maille" dans la structure de type GSList*


A partir de la fonctionn lecture la liste est censée contenir qqch:


GSList *lecture (char* chemin_un, char* chemin_deux)
{
  GSList *B = NULL;
  FILE* f = fopen(chemin_un, "r");
  FILE* g = fopen(chemin_deux,"r");
 
  if ((f) && (g))

  {
            while ((A->justification =! EOF) || (A->montant =! "\0"))
        {
      A = create_maille((lire_a(f)),(lire_num(g)));
      B = g_slist_append ( B,A);
        }
  }
  else
  {
    printf("hoho");
  }

  fclose(f); fclose(g);

  return B;
}

 


(J'aimerais pouvoir en plus faire entrer des données par l'utilisateur avec un  gtk_entry mais c'est un autre probleme);

#9 Re : Scripts, programmes et robots » error: ‘GSList’ {aka ‘struct _GSList’} has no member named ‘A » 29-01-2020 23:23:33

Clem
La declaration de structure/


struct bourse
{
  char *justification;
  int montant;
  char saut;

};

typedef struct bourse * maille;
 


J'ai une fonction de lecture et une d'écritue et c'est cette derniere qui ne marche as je ne comprend pas.

J'initialise A(maille) ainsi:


maille create_maille (char *justification, int montant)
{

    maille A = malloc(sizeof(struct bourse));
    A->justification = justification;
    A->montant = montant;
    A->saut: "\n";

    return A;
}
 



Et l'intégralité de la fonction qui pose probleme:


void ecriture ( GSList* B, char* chemin_un, char* chemin_deux)
{

    FILE* f = fopen(chemin_un, "w");
    FILE* g = fopen(chemin_deux,"w");
   

    if ((f) && (g))
    {
  while ( (B) =! NULL)
  {
      ecrire_char (f, B->maille->justification);
      ecrire_num (g, B->maille->montant);
      destr_maille (*B->maille);;
      B = g_slist_remove (B, B->maille);
  }
  g_slist_free(B);
    }
    else
    {
  printf("Blabla");
    }

    fclose(f); fclose (g);

}

 



Elle vide au fur et a mesure le contenu de la liste dans deux fichiers jusqu'a l'extinction;

#10 Scripts, programmes et robots » error: ‘GSList’ {aka ‘struct _GSList’} has no member named ‘A » 26-01-2020 19:01:26

Clem
Réponses : 5
Bonjour,
J'ai ce bout de code qui me fait suer :


if ((f) && (g))
    {
  while ( B =! NULL)
  {
      ecrire_char (f, B->A->justification);
      ecrire_num (g, B->A->montant);
      destr_maille (&B->A);;
      B = g_slist_remove (B, B->A);
  }
  g_slist_free(B);
    }
 



la compilation me renvoie :


list.c: In function ‘ecriture’:
list.c:95:12: error: assignment to ‘GSList *{aka ‘struct _GSList *} from ‘int’ makes pointer from integer without a cast [-Werror=int-conversion]
  while ( B =! NULL)
            ^
list.c:95:10: error: suggest parentheses around assignment used as truth value [-Werror=parentheses]
  while ( B =! NULL)
          ^
list.c:97:23: error: ‘GSList’ {aka ‘struct _GSList’} has no member named ‘A’
      ecrire_char (f, B->A->justification);
                       ^~
list.c:98:22: error: ‘GSList’ {aka ‘struct _GSList’} has no member named ‘A’
      ecrire_num (g, B->A->montant);
                      ^~
list.c:99:22: error: ‘GSList’ {aka ‘struct _GSList’} has no member named ‘A’
      destr_maille (&B->A);;
                      ^~
list.c:100:30: error: ‘GSList’ {aka ‘struct _GSList’} has no member named ‘A’
      B = g_slist_remove (B, B->A);
                              ^~
cc1: all warnings being treated as errors

 



B est une GSList et A un pointeur sur une stucture de deux champs (char* et int ). Cette structure A est le "data" de la liste.

#14 Re : Scripts, programmes et robots » error: variable ‘sep’ set but not used [-Werror=unused-but-set-variabl » 14-01-2020 16:03:55

Clem

raleur a écrit :

Une valeur est affectée à la variable locale mais elle n'est pas utilisée. Si tu n'utilises pas la valeur de retour de la fonction, inutile de l'affecter à une variable.


Il doit y avoir quelque chose a comprendre que je ne comprends pas.
Désolé, je débute.

#15 Re : Scripts, programmes et robots » error: variable ‘sep’ set but not used [-Werror=unused-but-set-variabl » 14-01-2020 13:37:46

Clem
Quand je compile avec les options
<-Werror -Wall -ansi> et a plus forte raison avec <-Werror=unused-but-set-variable> j'ai des retours d'eeeur.


[13:31:16] clem@Sid >> gcc `pkg-config --cflags gtk+-3.0` Ram/neuneu.c -o Ram/neuneu `pkg-config --libs gtk+-3.0` -W -Werror -Wall -ansi
Ram/neuneu.c: In function ‘activate’:
Ram/neuneu.c:27:16: error: variable ‘sep’ set but not used [-Werror=unused-but-set-variable]
   27 |     GtkWidget* sep;
      |                ^~~
Ram/neuneu.c:24:46: error: unused parameter ‘user_data’ [-Werror=unused-parameter]
   24 | void activate (GtkApplication *app, gpointer user_data)
      |                                     ~~~~~~~~~^~~~~~~~~
Ram/neuneu.c: In function ‘make_sep’:
Ram/neuneu.c:64:1: error: control reaches end of non-void function [-Werror=return-type]
   64 | }
      | ^
cc1: all warnings being treated as errors

 


Par contre ça râle mais ça marche.

#16 Re : Scripts, programmes et robots » error: variable ‘sep’ set but not used [-Werror=unused-but-set-variabl » 13-01-2020 17:19:16

Clem
Ce code visait juste a presenter un separateur sur une fenetre en factorisant un peu.



#include <stdio.h>
#include <gtk/gtk.h>

void activate (GtkApplication *app, gpointer user_data);
GtkWidget* make_master_window (GtkApplication* app, char* nom, int longueur, int profondeur);
GtkWidget* make_sep (GtkOrientation orientation, GtkWidget *contenant);

int main ( int argc, char **argv)
{
  GtkApplication *app;
  int status;

  app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
  g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
  status = g_application_run (G_APPLICATION(app), argc, argv);

  return status;

}


void activate (GtkApplication *app, gpointer user_data)
{

    GtkWidget* sep;
 
    GtkWidget *hbox;

    GtkWidget* window;

  window =  make_master_window (app,"neuneu",100,200);

  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL,5);
  gtk_container_add(GTK_CONTAINER(window), hbox);

  sep = make_sep (GTK_ORIENTATION_HORIZONTAL, hbox);

  gtk_widget_show_all(window);

}


GtkWidget* make_master_window (GtkApplication* app, char* nom, int longueur, int profondeur)
{
  GtkWidget* window;

  window = gtk_application_window_new(app);

  gtk_window_set_title (GTK_WINDOW (window),nom);
  gtk_container_set_border_width (GTK_CONTAINER( window), 10);
  gtk_window_set_default_size (GTK_WINDOW (window), longueur, profondeur);
 
  return window;
}

GtkWidget* make_sep (GtkOrientation orientation, GtkWidget *contenant)
{
    GtkWidget* sep;

  sep = gtk_separator_new (orientation);
  gtk_box_pack_start(GTK_BOX(contenant), sep, FALSE, FALSE, 5);

}
 


Et la ça marche o.O

Ps : oui ça marche nickel, je me suis encore trouvé des problèmes la ou il n'y en avait pas.

#17 Re : Scripts, programmes et robots » error: variable ‘sep’ set but not used [-Werror=unused-but-set-variabl » 13-01-2020 13:39:16

Clem
A l'nterieur de a fonction auxilliaire,la variable est bien utilisée;


GtkWidget* make_sep (GtkOrientation orientation, GtkWidget *contenant)
{
  GtkWidget * sep;

  sep = gtk_separator_new (orientation);
  gtk_box_pack_start(GTK_BOX(contenant), sep, FALSE, FALSE, 5);

  return sep;
}
 



Puisqu'elle renvoie un pointeur sur la variable, ça devrait être pris en compte, non?

Sii j'empaquette le sep dans une box, c'est la box a son tour d'être " set but not used".

Je dois en conculre qu'en l'état ce code n'est pas factorisable?

#18 Scripts, programmes et robots » error: variable ‘sep’ set but not used [-Werror=unused-but-set-variabl » 12-01-2020 15:33:43

Clem
Réponses : 11
Bon, j'ai repris a zéro, histoire d'y voir plus clair.

J'ai ce code:


#include <stdlib.h>
#include <stdio.h>
#include <gtk/gtk.h>

GtkWidget* make_sep (GtkOrientation orientation, GtkWidget *contenant);
void activate (GtkApplication *app, gpointer user_data);
GtkWidget* make_master_window (GtkApplication* app, char* nom, int longueur, int profondeur);

int main ( int argc, char **argv)
{
  GtkApplication *app;
  int status;

  app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
  g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
  status = g_application_run (G_APPLICATION(app), argc, argv);

  return status;

}


void activate (GtkApplication *app, gpointer user_data)
{
  GtkWidget* win;
  GtkWidget* sep;

  win = make_master_window ( app, "neuneu", 100, 200);

  sep = make_sep(GTK_ORIENTATION_HORIZONTAL, win);


  gtk_widget_show_all(win);

}


GtkWidget* make_master_window (GtkApplication* app, char* nom, int longueur, int profondeur)
{
  GtkWidget* window;

  window = gtk_application_window_new(app);

  gtk_window_set_title (GTK_WINDOW (window),nom);
  gtk_container_set_border_width (GTK_CONTAINER( window), 10);
  gtk_window_set_default_size (GTK_WINDOW (window), longueur, profondeur);
 
  return window;
}

GtkWidget* make_sep (GtkOrientation orientation, GtkWidget *contenant)
{
  GtkWidget * sep;

  sep = gtk_separator_new (orientation);
  gtk_box_pack_start(GTK_BOX(contenant), sep, FALSE, FALSE, 5);

  return sep;
}


 


Qui me renvoit


am/top.c: In function ‘activate’:
Ram/top.c:26:13: error: variable ‘sep’ set but not used [-Werror=unused-but-set-variable]
  GtkWidget* sep;
 


Je ne comprends pas, ma variable *sep est bien la:


Void activate (GtkApplication *app, gpointer user_data)
{
  GtkWidget* win;
  GtkWidget* sep;

  win = make_master_window ( app, "neuneu", 100, 200);

  sep = make_sep(GTK_ORIENTATION_HORIZONTAL, win);


  gtk_widget_show_all(win);

}
 



Je ne sais plus ou chercherscratchhead.gif

#19 Re : Scripts, programmes et robots » factorisation et pointeurs de fonction ( en c ) » 11-01-2020 17:03:55

Clem

raleur a écrit :


Quant à l'expression à droite de button =, je ne comprends pas sa finalité. Tu n'aurais pas oublié le nom de la fonction ?



J'ai oublié des morceau. Il faut lire


button = make_button ("parametre", hbox, say_hello, en_travaux, window);
 
 

#20 Re : Scripts, programmes et robots » factorisation et pointeurs de fonction ( en c ) » 11-01-2020 16:41:22

Clem
J'ai r"epris a zéro ôr isoler les erreurs.
Ce code:


GtkWidget *win;
  GtkWidget *vbox, *hbox;
  GtkWidget *sep;
  GtkWidget *frame;
  GtkWidget* label;


  win = make_master_window (app, "feuille", 200,300);

  vbox = make_box (win, GTK_ORIENTATION_VERTICAL);
  hbox = make_box (vbox, GTK_ORIENTATION_HORIZONTAL);
  frame = make_frame ("Bidouille", hbox);
  label = make_label (frame, "hahaha");
  frame = make_frame ("Machin", hbox);
  label = make_label (frame, "hohoho");


  sep = make_sep ( GTK_ORIENTATION_HORIZONTAL, vbox);
  hbox = make_box (vbox, GTK_ORIENTATION_HORIZONTAL);
  frame = make_frame ("Feuille", vbox);
  frame = make_frame ("Beton", vbox);

  sep = make_sep ( GTK_ORIENTATION_HORIZONTAL, vbox);
  frame = make_frame ("Buisson", vbox);
 
  gtk_widget_show_all(win);
}

 





GtkWidget* make_label (GtkWidget* contenant, char *lbl)
{
  GtkWidget* label;
  label = gtk_label_new (lbl);
  gtk_container_add ( GTK_CONTAINER (contenant), label);

  return label;
}

GtkWidget* make_master_window (GtkApplication* app, char* nom, int longueur, int profondeur)
{
  GtkWidget* window;

  window = gtk_application_window_new(app);

  gtk_window_set_title (GTK_WINDOW (window),nom);
  gtk_container_set_border_width (GTK_CONTAINER( window), 10);
  gtk_window_set_default_size (GTK_WINDOW (window), longueur, profondeur);
 
  return window;
}
GtkWidget* make_box ( GtkWidget* contenant, GtkOrientation orientation)
{
  GtkWidget *box;
  box = gtk_box_new (orientation, 10);
  gtk_box_pack_start(GTK_BOX (contenant), box, FALSE, FALSE, 5);

  return box;
}

GtkWidget* make_sep (GtkOrientation orientation, GtkWidget *contenant)
{
  GtkWidget* sep;

  sep = gtk_separator_new (orientation);
  gtk_box_pack_start ( GTK_BOX(contenant), sep, FALSE, FALSE, 5);

  return sep;
}

GtkWidget* make_frame (char *nom, GtkWidget* contenant)
{
  GtkWidget* frame;
frame = gtk_frame_new(nom);
  gtk_box_pack_start(GTK_BOX (contenant), frame, FALSE, FALSE, 5);

  return frame;
}


 


me renvoit:


clem@debian:~$ gcc -Wall -Werror -ansi `pkg-config --cflags gtk+-3.0` Ram/niou.c -o Ram/niou `pkg-config --libs gtk+-3.0`
Ram/niou.c: In function ‘activate’:
Ram/niou.c:31:13: error: variable ‘label’ set but not used [-Werror=unused-but-set-variable]
  GtkWidget* label;
             ^~~~~
Ram/niou.c:29:13: error: variable ‘sep’ set but not used [-Werror=unused-but-set-variable]
  GtkWidget *sep;
             ^~~
cc1: all warnings being treated as errors

 


Pourtant les variables en question sont utilisés.

#21 Re : Scripts, programmes et robots » factorisation et pointeurs de fonction ( en c ) » 11-01-2020 16:31:46

Clem
Bonjour smile

J'ai ceci comme erreur en particulier :


Ram/tirelire2.c:119:9: error: assignment to ‘GtkWidget *{aka ‘struct _GtkWidget *} from ‘int’ makes pointer from integer without a cast [-Werror=int-conversion]
  button =  make_button ( "Nouveau", hbox, &say_hello, &make_win, window);
         ^
Ram/tirelire2.c:120:9: error: assignment to ‘GtkWidget *{aka ‘struct _GtkWidget *} from ‘int’ makes pointer from integer without a cast [-Werror=int-conversion]
  button =  make_button ( "Parametres", hbox, &say_hello, &make_win, window);
         ^
Ram/tirelire2.c:121:9: error: assignment to ‘GtkWidget *{aka ‘struct _GtkWidget *} from ‘int’ makes pointer from integer without a cast [-Werror=int-conversion]
  button =  make_button ( "Quit", hbox, &say_goodbye, gtk_widget_destroy, window);

 

#22 Scripts, programmes et robots » factorisation et pointeurs de fonction ( en c ) » 10-01-2020 14:58:35

Clem
Réponses : 6
Bonjour a tous

j'essaaie de fatoriser la creation de boutons avec gtk3 et je me retrouve avec des erreur lies aux pointeurs de fonction

Le code factorisé ressemble a ça :


GtkWidget* create_button (char* nom, GtkWidget* contenant,
      (void) (*func_un) (void), (void) (*func_deux) (void), GtkWidget* window)
{
  button = gtk_button_new_with_label(nom);
  g_signal_connect (button, "clicked", G_CALLBACK (func__un), NULL);
  g_signal_connect_swapped (button, "clicked", G_CALLBACK (func_deux), window);
  gtk_container_add (GTK_CONTAINER (contenant), button);
  gtk_box_pack_start(GTK_BOX(contenant),button, FALSE,FALSE,5);
 



et les erreurs :


4: error: expected declaration specifiers or ‘...’ before ‘(’ token
    (void) (*func_un) (void), (void) (*func_deux) (void), GtkWidget* win)
    ^
Ram/tirelire3.c:166:30: error: expected declaration specifiers or ‘...’ before ‘(’ token
    (void) (*func_un) (void), (void) (*func_deux) (void), GtkWidget* win)
                              ^

 



Je n'arrive ppas a comprendre ou est le problème help.gif

si je fais la factorisation:


 button = ("parametre", hbox, say_hello, en_travaux, window);
 



J'obtiens ça:


gcc -Wall -Werror -ansi `pkg-config --cflags gtk+-3.0` Ram/tirelire3.c -o Ram/tirelire3 `pkg-config --libs gtk+-3.0`

Ram/tirelire3.c:12:4: error: expected declaration specifiers or ‘...’ before ‘(’ token
    (void) (*func_un) (void), (void) (*func_deux) (void), GtkWidget* window);
    ^
Ram/tirelire3.c:12:30: error: expected declaration specifiers or ‘...’ before ‘(’ token
    (void) (*func_un) (void), (void) (*func_deux) (void), GtkWidget* window);
                              ^
Ram/tirelire3.c: In function ‘activate’:
Ram/tirelire3.c:151:24: error: left-hand operand of comma expression has no effect [-Werror=unused-value]
   button = ("parametre", hbox, say_hello, en_travaux, window);
                        ^
Ram/tirelire3.c:151:30: error: left-hand operand of comma expression has no effect [-Werror=unused-value]
   button = ("parametre", hbox, say_hello, en_travaux, window);
                              ^
Ram/tirelire3.c:151:41: error: left-hand operand of comma expression has no effect [-Werror=unused-value]
   button = ("parametre", hbox, say_hello, en_travaux, window);
                                         ^
Ram/tirelire3.c:151:53: error: left-hand operand of comma expression has no effect [-Werror=unused-value]
   button = ("parametre", hbox, say_hello, en_travaux, window);
                                                     ^
Ram/tirelire3.c: At top level:
Ram/tirelire3.c:164:4: error: expected declaration specifiers or ‘...’ before ‘(’ token
    (void) (*func_un) (void), (void) (*func_deux) (void), GtkWidget* window)
    ^
Ram/tirelire3.c:164:30: error: expected declaration specifiers or ‘...’ before ‘(’ token
    (void) (*func_un) (void), (void) (*func_deux) (void), GtkWidget* window)
                              ^
cc1: all warnings being treated as errors

 

#23 Re : Scripts, programmes et robots » C gtk3 et frames contenant une liste de label » 01-01-2020 15:01:17

Clem
Tilt , ça y est j'ai compris big_smile
Les emboitement, les orientations toussa
J'ai fini par parvenir a ce que je veux
https://framapic.org/8a9YLlbb6m3T/96h3cAQ3s7x2.png


#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>

void activate (GtkApplication *app, gpointer user_data);

int main ( int argc, char **argv)
{
  GtkApplication *app;
  int status;

  app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
  g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
  status = g_application_run (G_APPLICATION(app), argc, argv);

  return status;

}


void activate (GtkApplication *app, gpointer user_data)
{
  GtkWidget *window;
  GtkWidget *frame;
  GtkWidget *sep;
  GtkWidget *vbox, *hbox;
  GtkWidget *label;

  window = gtk_application_window_new(app);
  gtk_window_set_title (GTK_WINDOW (window),"Machin");
  gtk_container_set_border_width (GTK_CONTAINER  ( window), 10);
  gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);

  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10);
  gtk_container_add (GTK_CONTAINER (window), vbox);
 
  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
  gtk_box_pack_start(GTK_BOX (vbox), hbox, FALSE, FALSE, 5);
 
  sep = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
  gtk_box_pack_start(GTK_BOX (vbox), sep, FALSE, FALSE, 5);


  frame = gtk_frame_new("L'hiver");
  gtk_container_add (GTK_CONTAINER (hbox), frame);
  gtk_box_pack_start(GTK_BOX (hbox), frame, FALSE, FALSE, 5);


  label = gtk_label_new ("Feuilles mortes :\n"
      "Feuilles vives :\n"
      "matins mornes :\n");
  gtk_container_add ( GTK_CONTAINER (frame), label);

  frame = gtk_frame_new("L'été");
  gtk_box_pack_start(GTK_BOX (hbox), frame, FALSE, FALSE, 5);
   
  label = gtk_label_new ("Canicule :\n"
      "Flore cramée :\n"
      "Riviere coule :\n");
  gtk_container_add ( GTK_CONTAINER (frame), label);

  sep = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
  gtk_box_pack_start(GTK_BOX (vbox), sep, FALSE, FALSE, 5);

  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
  gtk_container_add (GTK_CONTAINER (vbox), hbox);
 

  frame = gtk_frame_new("Le printemps");
  gtk_container_add (GTK_CONTAINER (hbox), frame);
  gtk_box_pack_start(GTK_BOX (hbox), frame, FALSE, FALSE, 5);


  label = gtk_label_new ("Feuilles vives :\n"
      "grosse pluie :\n"
      "matins clair :\n");
  gtk_container_add ( GTK_CONTAINER (frame), label);

  frame = gtk_frame_new("L'automne");
  gtk_box_pack_start(GTK_BOX (hbox), frame, FALSE, FALSE, 5);
   
  label = gtk_label_new ("L'odeur :\n"
      "La grisaille:\n"
      "Les ronces :\n");
  gtk_container_add ( GTK_CONTAINER (frame), label);


  gtk_widget_show_all(window);
}


 


merci a toi, tout est plus clair maintenant smile
Une bonne année a toi aussi

#24 Re : Scripts, programmes et robots » C gtk3 et frames contenant une liste de label » 31-12-2019 16:01:07

Clem
Je déduis que ce qui ne colle pas ici (je tente de crer une box horizontale):


 sep = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
  gtk_container_add (GTK_CONTAINER (window), hbox);
  gtk_box_pack_start(GTK_BOX (hbox), sep, FALSE, FALSE, 5);
 



C'est de tenter de rajouter une box a la window?
gtk_container_add (GTK_CONTAINER (window), hbox);
  gtk_box_pack_start(GTK_BOX (hbox), sep, FALSE, FALSE, 5);

Les widget box et hbox ne peuvent pas exister ensemble dans le widget window .
C'est bien ça?

PS : Si mais ça ne résoud pas mon probleme.

#25 Re : Scripts, programmes et robots » C gtk3 et frames contenant une liste de label » 31-12-2019 15:00:34

Clem
Ok j'ai compris smile Merci

Il me reste un probleme.
Avec ce code:


 frame = gtk_frame_new("L'hiver");
  box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
  gtk_container_add (GTK_CONTAINER (window), box);
  gtk_box_pack_start(GTK_BOX (box), frame, FALSE, FALSE, 5);

  label = gtk_label_new ("Feuilles mortes :\n"
      "Feuilles vives :\n"
      "matins mornes :");
  gtk_container_add ( GTK_CONTAINER (frame), label);

  frame = gtk_frame_new("L'été");
  gtk_box_pack_start(GTK_BOX (box), frame, FALSE, FALSE, 5);
   
  label = gtk_label_new ("Canicule :\n"
      "Flore cramée :\n"
      "Riviere coule");
  gtk_container_add ( GTK_CONTAINER (frame), label);

  sep = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
  gtk_box_pack_start(GTK_BOX (box), sep, FALSE, FALSE, 5);

 



Le séparateur va a droite du deuxieme frame alors que je voudrais qu'il soit en dessous des deux, sur une nouvelle ligne.

Ps Non je n'ai pas compris en fait. L'execution me renvoit;


sep:331): Gtk-WARNING **: 15:06:55.865: Attempting to add a widget with type GtkBox to a container of type GtkApplicationWindow, but the widget is already inside a container of type GtkApplicationWindow, please remove the widget from its existing container first.
 


Du coup j'en déduit que c'est le même type de problème que précédemment.

Pied de page des forums

Propulsé par FluxBB