|
atoi and atof
?
#include <stdlib.h>
#include <stdio.h>
int main( void )
{
char *s; double x; int i; long l;
s = " -2309.12E-15"; /* Test of atof */
x = atof( s );
printf( "atof test: \"%s\"; float: %e\n", s, x );
s = "7.8912654773d210"; /* Test of atof */
x = atof( s );
printf( "atof test: \"%s\"; float: %e\n", s, x );
s = " -9885 pigs"; /* Test of atoi */
i = atoi( s );
printf( "atoi test: \"%s\"; integer: %d\n", s, i );
s = "98854 dollars"; /* Test of atol */
l = atol( s );
printf( "atol test: \"%s\"; long: %ld\n", s, l );
}
Bryce
---
Publitor, making Pubmed easy.
http://www.sohocode.com/publitor
|
|
|
|
|
Yeah, but like the man said, he wants to use locales, In some countries, a comma is used instead of a point between numbers.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
couldnt he query the locale settings for number separator and modify the above code?
"there is no spoon" biz stuff about me
|
|
|
|
|
Yeah, he may need to. Or use a stream perhaps ?
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
I'd like to completetly avoid using the STL for this, the IOStreams and locales are pretty iffy in terms of various implementations completeness.
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
|
|
|
|
|
You need to compile on more than one compiler ?
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Yes, more than likely, and even if people use VC++ they may choose to use different STL Implementations, and the locale's support is the weakest part of the IOStream impl - some are good some are incomplete
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
|
|
|
|
|
Would it make sense if I got the various separator(s) characters from Win32, and then remove all the separators, get the decimal char from Win32 and replace it with a '.' char and then use the atof or atoi functions ?
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
|
|
|
|
|
Yeah, I suppose that would be a brute force, inelegant way of doing it. It may well be your best bet, but it would sure be nicer if the code in question knew what it was looking at, if you see what I mean.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Yeah, but I can't think of any other reliable way to do it - a pity the Win32 locale functions don't handle this.
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
|
|
|
|
|
Per MSDN, atof() will do this as it respects the locale settings. You may need to call setlocale() first, however. I tried this and it indeed works (i.e., converted "123,45" to 123.45).
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
Whats the easiest way to download a web page. I dont want to view it. I just want to download to my desktop for example, then I will process it.
Like, for instance, I want to download www.mywebpage.com\test.html (just an example) to
my desktop.
|
|
|
|
|
Right click on the link, Save Target As...
"Another day done - All targets met; all systems fully operational; all customers satisfied; all staff keen and well motivated; all pigs fed and ready to fly" - Jennie A.
|
|
|
|
|
Thanks for the reply. I shouldve said that I need to download it using VC++.
I'm not familiar with sockets and it seems simple to do but it may not be.
|
|
|
|
|
|
|
hi,
use CHttpSession,CHttpConnection,CHttpFile. using these class u can able to read the content from the server. It's the easiest way.
Have A Nice Day
Murali.M
|
|
|
|
|
Did you mean CInternetSession or CHttpSession itself !!
greatest thing is to do wot others think you cant suhredayan@omniquad.com
|
|
|
|
|
Hi,
that's CInternetSesssion not CHttpSession.
Have A Nice Day!
Murali.M
|
|
|
|
|
|
Hi,
I should like know, what compiler for C/C++ that i can to use for compile the programs (C/C++) showed in this site?
----
How to do a equation editor, type, M$ Word Equation, or MathType, etc?
tanks.
|
|
|
|
|
OCARA wrote:
I should like know, what compiler for C/C++ that i can to use for compile the programs (C/C++) showed in this site?
Various code here will be more or less forgiving, a lot of my articles will compile on any C++ compiler, as they are about standard C++. Most will require Microsoft Visual Studio 6.0 or .NET.
OCARA wrote:
How to do a equation editor, type, M$ Word Equation, or MathType, etc?
Seriously dude, if you can't work out that a site that has articles on programming the Microsoft platform will need the Microsoft compiler, even if sommeone was silly enough to attempt the huge answer required for such a broad question, the odds of you understanding the answer are close to zero.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
OCARA wrote:
How to do a equation editor, type, M$ Word Equation, or MathType, etc?
This article should help for this one.
http://www.codeproject.com/miscctrl/formulactrl.asp?target=equation%7Ceditor[^]
Roger Allen - Sonork 100.10016
Roger Wright: Remember to buckle up, please, and encourage your friends to do the same. It's not just about saving your life, but saving the quality of life for those you may leave behind...
|
|
|
|
|
tanks, tanks.
I going to try include LaTeX export...
|
|
|
|
|
Hello folks,
just moved from unix environment into win32, not quite comfortable with the feeling that i'm a dumb yet again
please, help! i need to get a full path to user's dir's like "My Documents". How can i do that? Just hardcoding the path "c:\\Documents and Settings\\USER_NAME_WHO_THE_HELL_KNOWS\\My Documents" is not good idea at all. And what about compatibility with different windowses (nt, xp, win2k or even win98)?
any help is greatly appreciated
alex,
debug - is my life style
|
|
|
|