cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
How to compare char* pointer with a rang
How to compare char* pointer with a range?
Sep 19, 2013 at 1:46am UTC
LuckyIsDog
(44)
I understand you can do
1
2
3
4
char
* charpointer[2]; charpointer =
"12"
;
if
(charpointer[0] ==
'1'
){ }
but how can we test for a range? 0-1? so I can compare it to '12'
I wouldn't want to do charpointer[0] == '1' && charpointer[1] == '2' though.
Sep 19, 2013 at 2:05am UTC
TheIdeasMan
(6817)
Use a C library function -
strcmp
There are other versions which are safer to use though.
If using C++ and you can get away with not using char arrays - that is no specific need to use them (like having to interface with an API), then use the STL string class.
C strings (char arrays)
http://www.cplusplus.com/reference/cstring/
C++ string class:
http://www.cplusplus.com/reference/string/
Good Luck!!
EDIT:
I found this, there are others to google if interested:
http://insanecoding.blogspot.com.au/2007/03/methods-for-safe-string-handling.html
Last edited on
Sep 19, 2013 at 2:12am UTC
Topic archived. No new replies allowed.