[RESOLVED] How to access the value to which const char* const points?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: [RESOLVED] How to access the value to which const char* const points?

Hybrid View

  1. #1
    Join Date
    Nov 2012
    Posts
    4

    [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.

  2. #2
    Join Date
    Nov 2012
    Posts
    4

    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).

  3. #3
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,067

    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)

  4. #4
    Join Date
    Nov 2012
    Posts
    4

    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?

  5. #5
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,067

    Re: How to access the value to which const char* const points?

    Quote Originally Posted by monday-to-friday View Post
    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.

  6. #6
    Join Date
    Nov 2012
    Posts
    4

    Re: How to access the value to which const char* const points?

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center