* Some troubles with dynamic structures ;-(
@ 2004-01-22 20:23 Alphex K.
2004-01-23 0:02 ` Glynn Clements
0 siblings, 1 reply; 3+ messages in thread
From: Alphex K. @ 2004-01-22 20:23 UTC (permalink / raw)
To: linux-c-programming
Hi, guys
I'm develop some program using gtk+ with dynamic structures
I'm have some problem with dynamic structures in thi code:
--
#include "oaptypes.h"
OapClient *clients;
OapClient * AddClient(OapClient * clientpointer,
int id,const char *nname,char *nmainsname,
char *nemail,char *naddress,char *noffaddress,
char *nicq,char *ninn,char *nphone,int nstatus,
char *nnotes) // this function add a new structure
{
OapClient * tt=clientpointer;
// check and to dynamic structure (begin)
if (clientpointer!=NULL)
{
while (clientpointer->next!=NULL)
clientpointer=clientpointer->next;
clientpointer->next=(struct OapClient *) malloc(sizeof (OapClient));
clientpointer=clientpointer->next;
clientpointer->next=NULL;
clientpointer->cid=id;
/*debugl*/ printf("name is:%s\n",nname);
clientpointer->name=nname;
/*debugl*/ printf("in db name is:%s\n",clientpointer->name);
clientpointer->mainsname=nmainsname;
clientpointer->email=nemail;
clientpointer->address=naddress;
clientpointer->offaddress=noffaddress;
clientpointer->icq=nicq;
clientpointer->inn=ninn;
clientpointer->phone=nphone;
clientpointer->status=nstatus;
clientpointer->notes=nnotes;
return tt;
}
else
{
clientpointer=(struct OapClient *) malloc(sizeof (OapClient));
/*debug8*/ //clientpointer=malloc(4096);
clientpointer->next=NULL;
clientpointer->cid=id;
clientpointer->name=nname;
clientpointer->mainsname=nmainsname;
clientpointer->email=nemail;
clientpointer->address=naddress;
clientpointer->offaddress=noffaddress;
clientpointer->icq=nicq;
clientpointer->inn=ninn;
clientpointer->phone=nphone;
clientpointer->status=nstatus;
clientpointer->notes=nnotes;
return clientpointer;
}
// end
}
// interface functions section
void _AddClient(void) //this function add a new structure, variables from gtk face =)
{
int astatus;
int aid;
char *aname;
char *amainsname;
char *aemail;
char *aaddress;
char *aoffaddress;
char *aicq;
char *ainn;
char *aphone;
char *anotes;
// get values from "add client" win
aname=gtk_entry_get_text(GTK_ENTRY(namecentry));
/*debugh*/ printf("name from entry is:%s\n",aname);
/*debug1*/ //sprintf(aname,"Default");
amainsname=gtk_entry_get_text(GTK_ENTRY(mainercentry));
aemail=gtk_entry_get_text(GTK_ENTRY(emailcentry));
aaddress=gtk_entry_get_text(GTK_ENTRY(physaddrentry));
aoffaddress=gtk_entry_get_text(GTK_ENTRY(offaddrentry));
aicq=gtk_entry_get_text(GTK_ENTRY(icqentry));
ainn=gtk_entry_get_text(GTK_ENTRY(innentry));
aphone=gtk_entry_get_text(GTK_ENTRY(phoneentry));
anotes=gtk_entry_get_text(GTK_ENTRY(notesentry));
// for debug only
astatus=0;
//for test only
aid=12;
// so and add values to the client db
clients=AddClient(clients,aid,aname,amainsname,aemail,
aaddress,aoffaddress,aicq,ainn,aphone,
astatus,anotes);
/*debug1*/ //free(aname);
}
void _FillClientsTable(OapClient *pointer) // it read from dynamic structure and fill gtk_clist
{
gchar *entr[4]; /*to fill*/
// adding to table
if (pointer!=NULL)
{
while(pointer!=NULL)
{
entr[0]=malloc(4);
sprintf(entr[0],"%d",clients->cid);
entr[1]=malloc(4);
sprintf(entr[1],"%d",clients->status);
//entr[0]=pointer->icq;
//entr[1]=pointer->icq;
/*debugj*/ printf("DEBUG: in db ->%s\n",pointer->name);
entr[2]=(char *)pointer->name;
/*debugj*/ printf("DEBUG: in entr ->%s\n",entr[2]);
entr[3]=pointer->mainsname;
entr[4]=pointer->email;
gtk_clist_append(GTK_CLIST(clclist),entr);
pointer=pointer->next;
free(entr[0]);
free(entr[1]);
}
}
}
--
so and structure
typedef struct
{
int cid;
char *name;
char *mainsname;
char *email;
char *address;
char *offaddress;
char *icq;
char *inn;
char *phone;
int status;
char *notes;
struct OapClient *next;
} OapClient;
--
Where I have a mistake,
integers in structure work normally, but
I'm have a problem with pointers to char
thanx
--
Alphex Kaanoken
Senior developer of Crew IT research labs
web: http://crew.org.ru
mailto:Alphex@Crew.Org.RU
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Some troubles with dynamic structures ;-(
2004-01-22 20:23 Some troubles with dynamic structures ;-( Alphex K.
@ 2004-01-23 0:02 ` Glynn Clements
2004-01-23 16:41 ` Alphex K.
0 siblings, 1 reply; 3+ messages in thread
From: Glynn Clements @ 2004-01-23 0:02 UTC (permalink / raw)
To: Alphex K.; +Cc: linux-c-programming
Alphex K. wrote:
> Where I have a mistake,
> integers in structure work normally, but
> I'm have a problem with pointers to char
The pointers are those returned from gtk_entry_get_text(), whose
documention says:
Retrieve the contents of the entry widget. The returned
pointer points to internally allocated storage in the widget
and must not be freed, modified or stored. For this reason,
this function is deprecated. Use gtk_editable_get_chars()
instead.
I take this as meaning that the data to which they point may become
invalid at the next operation to be performed on the GtkEntry (e.g.
the next time it receives a signal or is accessed via one of the
gtk_entry_* functions).
Use e.g. strdup() to copy the data, e.g.
aname=strdup(gtk_entry_get_text(GTK_ENTRY(namecentry)));
--
Glynn Clements <glynn.clements@virgin.net>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Some troubles with dynamic structures ;-(
2004-01-23 0:02 ` Glynn Clements
@ 2004-01-23 16:41 ` Alphex K.
0 siblings, 0 replies; 3+ messages in thread
From: Alphex K. @ 2004-01-23 16:41 UTC (permalink / raw)
To: Glynn Clements; +Cc: linux-c-programming
On Fri, 23 Jan 2004 00:02:15 +0000
Glynn Clements <glynn.clements@virgin.net> wrote:
>
> Alphex K. wrote:
>
> > Where I have a mistake,
> > integers in structure work normally, but
> > I'm have a problem with pointers to char
>
> The pointers are those returned from gtk_entry_get_text(), whose
> documention says:
>
> Retrieve the contents of the entry widget. The returned
> pointer points to internally allocated storage in the widget
> and must not be freed, modified or stored. For this reason,
> this function is deprecated. Use gtk_editable_get_chars()
> instead.
>
> I take this as meaning that the data to which they point may become
> invalid at the next operation to be performed on the GtkEntry (e.g.
> the next time it receives a signal or is accessed via one of the
> gtk_entry_* functions).
>
> Use e.g. strdup() to copy the data, e.g.
>
> aname=strdup(gtk_entry_get_text(GTK_ENTRY(namecentry)));
yes it's work normally, thanx
>
> --
> Glynn Clements <glynn.clements@virgin.net>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
--
Alphex Kaanoken
Senior developer of Crew IT research labs
web: http://crew.org.ru
mailto:Alphex@Crew.Org.RU
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2004-01-23 16:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-01-22 20:23 Some troubles with dynamic structures ;-( Alphex K.
2004-01-23 0:02 ` Glynn Clements
2004-01-23 16:41 ` Alphex K.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).