CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: pointers

  1. #1
    Join Date
    Dec 2003
    Location
    Syracuse, NY
    Posts
    400

    pointers

    Okay this is really making me mad. I have a pointer to a char(char *filename) and I want to assign that to a buffer(char buffer). I've tried looking around and tried what they put( buffer = &filename, etc..) but it still pops up an error
    Code:
    error C2440: 'initializing' : cannot convert from 'char **__w64  ' to 'char []'
    Please help.
    "Windows programming is like going to the dentist: You know it's good for you, but no one likes doing it."
    - Andre LaMothe

    DLL For Beginners(UPDATED)
    Please use CODE tags
    Rate me if I've helped.

  2. #2
    Join Date
    Dec 2004
    Location
    Poland
    Posts
    1,165

    Re: pointers

    Show us some code, someone will help then.
    B+!
    'There is no cat' - A. Einstein

    Use [code] [/code] tags!

    Did YOU share your photo with us at CG Members photo gallery ?

  3. #3
    Join Date
    Dec 2003
    Location
    Syracuse, NY
    Posts
    400

    Re: pointers

    Something like this:
    Code:
    char *string;
    char buffer = &string
    "Windows programming is like going to the dentist: You know it's good for you, but no one likes doing it."
    - Andre LaMothe

    DLL For Beginners(UPDATED)
    Please use CODE tags
    Rate me if I've helped.

  4. #4
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815

    Re: pointers

    Quote Originally Posted by Notsosuperhero
    Something like this:
    Code:
    char *string;
    char buffer = &string
    Well, there are two things wrong here: You are taking the address of the pointer (instead of just the pointer itself) and you are trying to assign it to a single character (not a buffer). In order to copy text characters pointed to by a char* to a char array, you should use strncpy().

  5. #5
    Join Date
    Sep 2001
    Location
    San Diego
    Posts
    2,147

    Re: pointers

    Your terminology is a little difficult to understand.

    A character pointer is a pointer to a series of characters in memory.

    A character array is storage space for such a series of characters.

    You said you have a pointer (possibly a char *) which you would like to assign to buffer (whatever that is).

    If you are trying to copy the characters from one place to another, you may need to use something like strcpy to perform a simple string copy. Before doing this, the buffer must be large enough to hold these characters being copied.

    Something like this should work...

    char *MyPointer = "Hello World";
    char MyBuffer[100];

    strcpy(MyBuffer, MyPointer);

    Hope this helps,

    - Nigel

  6. #6
    Join Date
    Oct 2002
    Location
    Singapore
    Posts
    3,128

    Re: pointers

    ... or doing it in the C++ way.

    Code:
    include <string>
    using namespace std;
    
    int main()
    {
        const char *myString = "Hello world";
        string anotherString(myString);
    
        return 0;
    }
    Last edited by Kheun; January 30th, 2005 at 10:27 PM.

  7. #7
    Join Date
    Dec 2003
    Location
    Syracuse, NY
    Posts
    400

    Re: pointers

    Thank you all. I was a little tired(OK really tired) when I was posting this.
    "Windows programming is like going to the dentist: You know it's good for you, but no one likes doing it."
    - Andre LaMothe

    DLL For Beginners(UPDATED)
    Please use CODE tags
    Rate me if I've helped.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured