1. Re: C to Euphoria
- Posted by Irv <irv at ELLIJAY.COM> Jul 11, 1998
- 424 views
Antoine Delle Donne wrote: > > > > How to convert these structures in Euphoria and will they > > > keep the same size as in C. For example structure IDNAME is > > > 162 bytes long Will it still be 162 bytes long in Euphoria? > > > > Euphoria does not have structures like C. > > Euphoria has atoms and sequences (only). > > I know Euphoria does not have structures that is why I would like to know > what would be the equivalent of this in Euphoria Style. > typedef struct { > unsigned int no; > char n[4][32]; > char tel[16],fax[16]; > } IDNAME; > Euphoria uses dynamic sizing for these things. Static sizes will take up more space, especially in the example you give (name/addr/phone number - which usually have a lot of short names and blank spaces). example 1: constant NO = 1, NAME = 2, ADDR = 3, CITY = 4, STATE = 5, TEL = 6, FAX = 7 sequence idname idname = repeat({},7) idname[NO] = 1000 idname[NAME] = "Joe Smith" idname[TEL] = "123-456-7890" etc... each "field" uses only the space required to store the data, not a fixed 32 bytes or whatever. If you have to read and write files created by C, there is a way to get around the dynamic sizing: To fix the lengths: idname[NAME] = repeat(" ",32) idname[TEL] = repeat(" ",16) etc... but, when you assign idname[NAME} = "Joe Smith", the length is adjusted downward to fit "Joe Smith". If for some reason you must maintain fixed length fields, you have to pad each ome to the proper length. printf(fn,"%32s",{idname[NAME]}) is one way. Expanded to the example above: printf(fn,"%d %32s %32s %32s %32s %16s %16s",{idname}) Use a minus sign ("%-32s") to left justify. You may want to take out the spaces, I left them in for readability. Hope this is what you were asking. There's an example program on my Euphoria ftp site: http://www.mindspring.com/~mountains (ftp download filename STOCK.ZIP) that does this kind of thing. Regards, Irv