Re: How to initialize fields
Posted in 2012
On 16/08/12 14:33, Francesco Alfano wrote: > I don't understand very well, > can you give me a sort of sample code ? > > If I using your example, how can I perform different initializations for > the numercic fields (initialized to 0) and alphanumeric (initialized to ' ') > > > Thanks for your response. > > Il 16/08/2012 15:21, Art S. Kagel ha scritto: >> >> You can use memset to null out the entire struct which will take care of >> the binary fields then one field at a time put a space into the first >> characters of the char fields. >> >> Sent from my Galaxy S®III >> >> Francesco Alfano <edacedpa@yahoo.it> wrote: >> Hi, >> How can I write a routine in Esql/C which initialize to 0 (zero) all >> numeric fields (smallint, decimal, etc) and to (' ') space the other >> fields in a table ? >> >> Thanks for your response. Sigh! typedef struct { int field1; char field2[10]; int field3; char field4[10]; char *field5; } foobar_t; ... foobar_t foobar; memset(&foobar, 0, sizeof(foobar)); foobar.field2[0] = ' '; foobar.field4[0] = ' '; foobar.field5 = malloc(sizeof(...something...)); if (foobar.field5) { memset(foobar.field5, 0, sizeof(...something...)); *foobar.field5 = ' '; } etc etc ('mbare, detto in lingua, ca fallo un poco di sforzo...) -- Ciao, Marco ______________________________________________________________________________ Marco Greco /UK /IBM Standard disclaimers apply! Structured Query Scripting Language http://www.4glworks.com/sqsl.htm 4glworks http://www.4glworks.com Informix on Linux http://www.4glworks.com/ifmxlinux.htm