Re: How to convert from string to char*?

Tech-Archive recommends: Speed Up your PC by fixing your registry



"Lorry Astra" <LorryAstra@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:654CE450-394B-4E24-967D-E8CDE85FBEF2@xxxxxxxxxxxxx
hi,
i have two questions:
1. How to convert from string to char*? I use c_str() of string, but
it returns "const char*" instead of char*;

One way is to create a char array and copy from c_str() to it.

2. When i use copy() function of string, i always get some unknown
characters from the first parameter (char*) after using copy()
function.(these unknow character is like "<<" or ">>", but my string
doesn't include these characters.)

Using copy won't nul-terminate the string, so you will get junk characters
after the characters you copy. If you use this approach, then you need to
nul-terminate manually. If this doesn't solve the problem, then post
(compileable) code showing what you are doing.

--
John Carson


.



Relevant Pages

  • Re: Is this string input function safe?
    ... return a pointer to mallocated memory holding one input string, ... See my comment after your call to fgets. ... char* malloc_getstr ... before any characters are read, then the ...
    (comp.lang.c)
  • Re: RfD: XCHAR wordset (for UTF-8 and alike)
    ... extended to work with xchars, ... >replacing one char with another. ... before-cursor part, even for fixed-width characters. ... So, should string words ...
    (comp.lang.forth)
  • RE: Fixed Length
    ... match these formats, but rather pull the existing, normal, formats from the ... and run a function to build that information into a string that you ... length and the total lenght of all the fields has to be 100 characters. ... JobId (8 char) ...
    (microsoft.public.access.modulesdaovba)
  • Re: Is this code totaly a shit?
    ... | void UppStrg(char *Low, char *Upp, int cnt); ... whitespace-delimited string. ... You're also assuming that the representations of the characters ...
    (comp.lang.c)
  • Re: Sorry, newbie question about generating a random string
    ... string grows to a max of 10 characters. ... The real problem is that you are not terminating the string. ... string is an array of characters ending in a null character, ... char myChar; ...
    (comp.lang.c.moderated)