Visit the LQ Articles and Editorials section
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


Search this Thread
Old 07-13-2006, 05:36 AM   #1
LQ Newbie
Registered: Jul 2006
Posts: 1

Rep: Reputation: 0
GLib problems with g_tree_insert()

Hi all,

I'm rebuilding a server written in C and using open-source GLib.
In particular, after initializing a tree, I would like to full it using the function g_tree_insert(), using a string as key and a struct as data. Here is the function:

void caricaValori(void) {
extern struct dbase head_db;
extern int revoche;
extern mpz_t espowa;
struct row *r1;
unsigned char str_xlow[DIM_STR_SERIALE],str_xhigh[DIM_STR_SERIALE],str_y[DIM_STR_Y],str_y_inv[DIM_STR_Y_INV],intestazione[DIM_INTESTAZIONE], str_in[DIM_STR_IN];
FILE *fd;
#ifdef DEBUG
printf("CARICA_VALORI: ... ");



if((fd = fopen(nomefile1,"r")) == NULL) {perror("Impossibile aprire il file db in lettura");raise(SIGINT);}
if(fgets(intestazione,DIM_INTESTAZIONE,fd)==NULL) {perror("Niente da leggere nel file db in lettura");}
do {
fscanf(fd,"%s %s %s %s\n",str_xlow,str_xhigh,str_y,str_y_inv);
r1=(struct row*)malloc(sizeof(struct row));
if(strlen(str_xlow)!=0 && strlen(str_xhigh)!=0 && strlen(str_y)!=0 && strlen(str_y_inv)!=0) {
mpz_init_set_str(r1->stat.xhigh,str_xhigh,BASE); // setta il parametro 1 dalla striga 2 con base BASE
mpz_init_set_str(r1->stat.y,str_y,BASE); // setta il parametro 1 dalla striga 2 con base BASE
r1->stat.valid_z=0; // z non �valido

if(head_db.tqh_first == NULL) { // TODO forse non importa
TAILQ_INSERT_HEAD(&head_db, r1, rows);
else {
TAILQ_INSERT_TAIL(&head_db, r1, rows);
else {
#ifdef DEBUG
printf("DB vuoto\n");
if(mpz_cmp_ui(espowa,1)!=0) {
perror("Valori di espowa non coerenti con DB vuoto (espowa!=1)");
if(revocaSeriale("0")<1) {
perror("Errore nella revoca di 0");
else revoche++;
} while (!feof(fd));
if(mpz_cmp_ui(head_db.tqh_first->stat.xhigh,0)!=0 && mpz_cmp_ui(espowa,1)==0) {
perror("Valori di espowa non coerenti con DB pieno (espowa=1)");

r1 = head_db.tqh_first;
while(r1 != NULL) {
mpz_get_str (str_xlow, BASE, r1->stat.xlow);
mpz_get_str (str_xhigh, BASE, r1->stat.xhigh);
strcpy(str_in, "");
//printf("%s\n", str_in);
g_tree_insert(tree, str_in, r1);
r1 = r1->rows.tqe_next;

g_tree_foreach(tree, (GTraverseFunc)iter_all, NULL);


This function opens a text file, reads it, fulls a list with all values. Then it is supposed to fill up the tree reading all those values contained in the list, but when I look up the tree with g_tree_foreach, I see that I can find in the tree only the last value, as if the previous values were somehow overwritten. I need instead to fill up the tree with all the values read from the list (the list contains all the values correctly). I'm using GNU MP too.
Please, can anyone help me?

Thanks in advance and sorry for my bad english!



glib, overwrite, tree

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
GLIB problems and more rochmndx Linux - Newbie 3 07-03-2005 12:18 PM
Problems with GLIB ??? burki Linux - Software 2 03-02-2005 04:58 PM
glib problems migu Mandriva 3 02-26-2005 05:02 PM
[GLIB] Problems Installing GLIB ThA_eLMo_GoD Linux - Newbie 2 09-04-2004 05:27 PM
Problems relating to glib 1.2.10 and glib 1.2.9 p3ngu!n Mandriva 10 05-23-2004 09:03 PM

All times are GMT -5. The time now is 11:58 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration