-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAtoi.cpp
More file actions
64 lines (52 loc) · 1.3 KB
/
Atoi.cpp
File metadata and controls
64 lines (52 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* \file Atoi.cpp
* \brief Convert Non-number values to int, double
*/
//---------------------------------------------------------------------------
#include <StdStream/StdStream.h>
#include <StdTest/StdTest.h>
#include <Stl.h>
//---------------------------------------------------------------------------
int main(int, char **)
{
const char *strInts []
{
"", "NULL", "ta", "13ta", "a31", "$27,41", "27,41"
};
for (const auto it_strInt : strInts) {
int a = std::atoi(it_strInt);
std::cout << STD_TRACE_VAR2(it_strInt, a) << std::endl;
}
{
#if 0
const char *strInt {nullptr};
int a = std::atoi(strInt);
std::cout << STD_TRACE_VAR2(strInt, a) << std::endl;
#endif
}
{
const char *strDouble {"$27,41 "};
/**
* Need for fix:
*
* - Remove - "$"
* - Replace - "," -> "."
*/
double a = std::strtod(strDouble, nullptr);
std::cout << STD_TRACE_VAR2(strDouble, a) << std::endl;
}
return EXIT_SUCCESS;
}
//---------------------------------------------------------------------------
#if OUTPUT
---------------------------------------------
it_strInt: , a: 0
it_strInt: NULL, a: 0
it_strInt: ta, a: 0
it_strInt: 13ta, a: 13
it_strInt: a31, a: 0
it_strInt: $27,41, a: 0
it_strInt: 27,41, a: 27
strDouble: $27,41 , a: 0
---------------------------------------------
#endif