[mercury-users] Filling Mercury strings in C
Petr Nemec
xanthar at seznam.cz
Tue Mar 25 23:18:36 AEDT 2003
Hello people,
does anybody know (sure he does :),how to fill the Mercury strings
in C properly? I use the attached code to read a line and to destroy
ending \n in C. But it seems the memory for the allocated strings is
not being freed at all during the computation. Do I allocate right :)
?
Thanks
Petr
:- pred creadstring(int,string).
:- mode creadstring(in,out) is semidet.
:-pragma
c_code(creadstring(Pointer::in,String::out),[will_not_call_mercury],
"
char buffer[MAX_LINE];
char* sDynamic;
if(fgets(buffer,MAX_LINE,(FILE*)Pointer) != NULL)
{
nLength = strlen(buffer);
buffer[nLength-1] = '\\0';
sDynamic = malloc(nLength);
strcpy(sDynamic,buffer);
String = sDynamic;
SUCCESS_INDICATOR = 1;
}
else
SUCCESS_INDICATOR = 0;
").
______________________________________________________________________
Reklama:
Vyzkousej zabavny test Travelmatch od KLM. Naleznes tak dovolenou svych
snu a usetrĂs 30%! Hraj zde: http://ad2.seznam.cz/redir.cgi?instance=45492%26url=http://klm.mhc.hu/travelmatch/cz/tm_lp_cz_cz.htm
--------------------------------------------------------------------------
mercury-users mailing list
post: mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the users
mailing list