copy LPCSTR type

This is a discussion on copy LPCSTR type within the Windows Programming forums, part of the Platform Specific Boards category; Hi I am having a problem to copy a LPCSTR string to the same type variable... I have allready tried ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    162

    copy LPCSTR type

    Hi

    I am having a problem to copy a LPCSTR string to the same type variable...

    I have allready tried
    Code:
    LPCSTR lpStringOne;
    LPCSTR lpStringTwo;
    
    lpStringOne = lpStringTwo;
    wsprintf(lpStringOne, "%s", lpStringTwo);
    strcpy(lpStringOne, lpStringTwo);
    Either function failed to work... When the programme came to the function it failed.

    Which function shall I use in case of LPCSTR?

    Thx for responses

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,855
    Well they're just pointers (you really need to understand "Hungarian Notation" as used by Microsoft to understand that).

    Somewhere along the line, you need to make those pointer point to a real string of some sort, or some actual space to store a string.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    I am having a problem to copy a LPCSTR string to the same type variable...
    That's probably because an LPCSTR is nothing more than a "const char*". You cannot write to it for two reasons: You will need a real array of chars and you will need a non-const pointer to it to use strcpy or sprintf.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  4. #4
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    try this -

    Code:
    LPCSTR lpStringOne;
    LPCSTR lpStringTwo;
     
    lpStringTwo = (LPCSTR)malloc(512);
    
    lpStringOne = lpStringTwo;
    wsprintf(lpStringOne, "%s", lpStringTwo);
    strcpy(lpStringOne, lpStringTwo);
     
    free(lpStringTwo);
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. scanf oddities
    By robwhit in forum C Programming
    Replies: 5
    Last Post: 09-22-2007, 02:03 AM
  2. Script errors - bool unrecognized and struct issues
    By ulillillia in forum Windows Programming
    Replies: 10
    Last Post: 12-18-2006, 04:44 AM
  3. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM
  4. Changing an objects Type
    By ventolin in forum C++ Programming
    Replies: 2
    Last Post: 06-29-2004, 08:18 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 07:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21