[RESOLVED] How to access the value to which const char* const points?
Hi,
I need to check if the pointer const char* const points to an empty string.
Something like this:
Code:
const char* const a = ...
if (&a == "") {
cout << "empty string!";
}
However, the code above gives me an error:
error C2446 '==': no conversion from 'const char*' to 'const char *const *'
so I guess I am doing something wrong.
Could someone help please?
Thanks.
Re: How to access the value to which const char* const points?
I mean I don't actually assign anything to 'a' myself (just realised that the line
Code:
const char* const a = ...
would probably not work and might just confuse everybody).
Re: How to access the value to which const char* const points?
& is the address of operator. Your code is attempting to get the address of a pointer. There are several options, assuming the pointer is not null, including...
if(a[0] == 0)
if(strlen(a) == 0)
Re: How to access the value to which const char* const points?
GCDEF, thanks for your reply.
I just found another option that seems to work:
if (*a == '\0')
Is this also a correct way?
Re: How to access the value to which const char* const points?
Quote:
Originally Posted by
monday-to-friday
GCDEF, thanks for your reply.
I just found another option that seems to work:
if (*a == '\0')
Is this also a correct way?
That's fine too.
Re: How to access the value to which const char* const points?