Operating System - HP-UX
1828346 Members
3232 Online
109976 Solutions
New Discussion

error while running a code

 
Arun_41
New Member

error while running a code

i am very new to hp-ux development.
i wrote the below code. it compiled fine, when i ran it exited eith the message

"Memory fault(coredump)"

#include
int main()
{
char *str;
int dec=0,sign=0;
int ndig=0;
ndig=8;
printf("before");
str=_ldecvt(234.9,ndig,&dec,&sign);
printf("%d %d",dec,sign);
return 0;
}

what could be the problem.
please help me.
4 REPLIES 4
harry d brown jr
Honored Contributor

Re: error while running a code


You are compiling with what?

What compile and possible load options did you use?

With gcc I got it to compile and run (executed a.out) with these results:
before3 0

with just a plain cc I got errors:
cc: "txt.c", line 9: error 1718: Types are not assignment-compatible.
cc: "txt.c", line 9: warning 563: Argument #1 is not the correct type.


live free or die
harry d brown jr
Live Free or Die
Stephen Keane
Honored Contributor

Re: error while running a code

Assuming you are using the cc compiler w/out ansi support, try the following ...


#include
int main()
{
char *str;
int dec=0,sign=0;
int ndig=0;
long_double value;

ndig=8;
value=strtold("234.9", NULL);

printf("before");
str=_ldfcvt(value, ndig, &dec, &sign);
printf("%d %d",dec,sign);
return 0;
}



But you really ought to get a proper compiler!
Rory R Hammond
Trusted Contributor

Re: error while running a code

_ldecvt(); evct();
I could not get the _ldecvt() library functions to work either. In the HP C/HP-UX reference manual Version A.06.00/A.05.60 page 205 it states that Functons names beginning with a underscore (_) are reserved for library use; you should not speify identifiers that begin with an underscore.

I was able to make your code work using "evct()" which appears to be an equilvant function.

#include
int main()
{
char *str;
int dec=0,sign=0;
int ndig=0;
ndig=8;
long double value=234.9;
(void) printf("before\n");
str=ecvt(value,ndig,&dec,&sign);
(void) printf("%s\n",str);
(void) printf("%d %d\n",dec,sign);
return 0;
}

Hope this helps.
Rory
There are a 100 ways to do things and 97 of them are right
Arun_41
New Member

Re: error while running a code

HI all,
Thanks for your reply.
The program is running fine.

Regards,
Arun