Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I have problems with casting operations! 1

Status
Not open for further replies.

frag

Programmer
Dec 7, 2000
321
GB
Hi!

I've got two problems with casting operations:

1. I want to cast a string to an int but if I do something like this:
intValue = (int)strText;
I'll get a wrong int value. For example:
string value: "372186"
int value : -268440556
I already tried it with an unsigned int... no chance!

2. How can I cast a string to a double?
dblValue = (double)strText;
Doesn't do the job!

has anybody an idea?

thanx!

frag


patrick.metz@epost.de
 
This comes directly from strtod man page:

NAME
strtod - convert ASCII string to double

SYNOPSIS
#include <stdlib.h>

double strtod(const char *nptr, char **endptr);

DESCRIPTION
The strtod() function converts the initial portion of the
string pointed to by nptr to double representation.

The expected form of the string is optional leading white
space as checked by isspace(3), an optional plus (``+'')
or minus sign (``-'') followed by a sequence of digits
optionally containing a decimal-point character, option­
ally followed by an exponent. An exponent consists of an
``E'' or ``e'', followed by an optional plus or minus
sign, followed by a non-empty sequence of digits. If the
locale is not &quot;C&quot; or &quot;POSIX&quot;, different formats may be

As always, I hope that helped!

Disclaimer:
Beware: Studies have shown that research causes cancer in lab rats.
 
Hi mbaranski!

This worked perfectly fine. I could solve my int problem too (by using atoi).

Thank you.

frag patrick.metz@epost.de
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top