1. Re: C to Euphoria

>> 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;

I think I understand what you want, although I don't have all the
details... maybe somebody else can fill those in.

In C, you can do something like this (not sure of all the syntax,
especially since you defined a structure differently from what I'm used
to, and the function names may be different and stuff, but you should get
the idea) :

void SaveData(struct *data, int datasize)
{
    FILE fn;
    fn = fopen("file", "wb");
    fwrite(fn, data, datasize);
    fclose(fn);
    return;
}

And down in the main():

    SaveData(datastuff, sizeof(datastuff));

This would save all 162 bytes to disk, and later be read back directly
into memory with fread(). You want the Euphoria version to have files
that are compatible with the C version of the program, right?


The solution: There are some functions in machine.e that may give you
what you want:

s = int_to_bytes(a)

Maybe some others could help, also..

Then you can print the bytes to a file using puts(1, s) or printf(1,
"%s", {s}) and have C's version of the representation on disk. (I think,
you have that int setup as unsigned, may take some extra coding...)

As for the strings, something like this:

printf(1, "%16s", {tel})


As for reading, you just read in the correct number of bytes and assign
them to the variables, and for numbers, use bytes_to_int() to convert the
4 bytes into and integer value.

Emulating C in Euphoria may be a bit extra work, but Euphoria doesn't
want to be C so it should be natural that way. ;)

Maybe you could write a .e file with the routines to do this stuff, but
with all the C types and everything (100% compatible).



_____________________________________________________________________
You don't need to buy Internet access to use free Internet e-mail.
Get completely free e-mail from Juno at http://www.juno.com
Or call Juno at (800) 654-JUNO [654-5866]

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu