Re: access variable...



Self replying as it seems to be working fine now... Here is the modified program... just to close the thread...

#include <stdlib.h>
#include <glib.h>

typedef struct
{
    gint i;
} _udata;

gboolean
tempo(gpointer data)
{
    gint j = 0;
    j = ((_udata*)data)->i;
    g_print("%d", j);
    //g_print("<%d> ", (gint)data);
    return TRUE;
}


gint
main(gint argc, gchar *argv[])
{
    GMainLoop *loop;
    _udata *udata = g_malloc(sizeof(_udata));
    udata->i = 1;
   
    g_print("Delay: %s. ", argv[1]);
    g_print("i: <%d>\n", udata->i);
    g_print("data: <%d>\n", (gint)udata);
    g_timeout_add(g_ascii_strtod(argv[1], NULL), (GSourceFunc)tempo, (gpointer)udata);
    loop =  g_main_loop_new(NULL, TRUE);
    g_main_loop_run(loop);
   
    return 0;
}


On 04/10/06, Yianni <odysseus lost gmail com> wrote:
Hi,

sorry for the silly question but how do I access the variables.... see my code below...

#include <stdlib.h>
#include <glib.h>

gboolean
tempo(gpointer data)
{
    gint j = 0;
    j = (gint)(data->i); // HOW TO ACCESS THE STRUCTURES VARIABLES???
    g_print("%d", j);
    return TRUE;
}


gint
main(gint argc, gchar *argv[])
{
    GMainLoop *loop;
    struct
    {
    gint i;
    } *udata;
    udata = g_malloc(sizeof(gint) + sizeof(gchar));
    udata->i = 1;
   
    g_print("Delay: %s. ", argv[1]);
    g_print("i: <%d>\n", udata->i);
    g_timeout_add(g_ascii_strtod(argv[1], NULL), (GSourceFunc)tempo, (gpointer)udata);
    loop =  g_main_loop_new(NULL, TRUE);
    g_main_loop_run(loop);
   
    return 0;
}


--
-- Yianni



--
-- Yianni

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]