How to compare char* pointer with a range?

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.
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
Topic archived. No new replies allowed.