Convert const char* to char*?

This is a discussion on Convert const char* to char*? within the C++ Programming forums, part of the General Programming Boards category; Is there a way to convert or copy a const char* to a char*? Google has failed me here....

  1. #1
    DmD
    DmD is offline
    Registered User
    Join Date
    May 2005
    Posts
    6

    Convert const char* to char*?

    Is there a way to convert or copy a const char* to a char*? Google has failed me here.

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,805
    Ummmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm mmmmmmmm.

    strcpy http://www.cplusplus.com/ref/cstring/strcpy.html
    Woop?

  3. #3
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    const_cast?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  4. #4
    DmD
    DmD is offline
    Registered User
    Join Date
    May 2005
    Posts
    6
    strcpy won't work with a const char* , and const_cast seems kind of unreliable.
    edit: I mean the strcpy in the source code for a game I'm modding. It has its own version.
    Last edited by DmD; 12-22-2005 at 09:23 PM.

  5. #5
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Okay let's play 20 questions. Or not. Why don't you post a minimal snippet of code that demonstrates what it is you are attempting to accomplish.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  6. #6
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,805
    Fine I will write it for you.
    Code:
    char *strcpy(char *dest, const char *src)
    {
        int i;
        for(i = 0; src[i] != '\0'; i++)
        {
            dest[i] = src[i];
        }
        dest[i] = '\0';
        
        return dest;
    }
    My life is now complete.
    Woop?

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,532
    > Is there a way to convert or copy a const char* to a char*?
    Lemme guess, it's the result of the c_str() method on one of your strings?

    > I mean the strcpy in the source code for a game I'm modding. It has its own version.
    So use it.
    Or does it have a completely different signature compared to the ANSI-C strcpy() ?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. The so annoying LNK2005... please help!
    By Mikey_S in forum C++ Programming
    Replies: 14
    Last Post: 02-01-2009, 03:22 AM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  3. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  4. Another problem with templates
    By robatino in forum C++ Programming
    Replies: 8
    Last Post: 09-21-2006, 04:32 PM
  5. fatal error LNK1104
    By DMH in forum C++ Programming
    Replies: 2
    Last Post: 11-16-2005, 02:46 AM

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