What is the best way to copy a Char* to a Char*?
Char* to Char*
Collapse
This topic is closed.
X
X
-
Jake ThompsonTags: None -
Keith Thompson
Re: Char* to Char*
"Jake Thompson" <readytoride39@ hotmail.com> writes:[color=blue]
> What is the best way to copy a Char* to a Char*?[/color]
That depends on what you mean.
There is no standard type Char; I presume you mean char.
To copy the value of a char* object to another one, just assign it.
To copy a string, use strcpy() (but first make sure that the target
has enough room).
If you're copying character arrays that aren't strings, use memcpy()
(or memmove() if they might overlap).
--
Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
-
Mike Wahler
Re: Char* to Char*
"Jake Thompson" <readytoride39@ hotmail.com> wrote in message
news:1136569581 .780724.149640@ g49g2000cwa.goo glegroups.com.. .[color=blue]
> What is the best way to copy a Char* to a Char*?[/color]
int main(void)
{
typedef char Char;
Char *a = 0;
Char *b = 0;
a = b;
return 0;
}
I've given a literal answer to your question.
I suspect you'll need to phrase it more specifically
to get the answer you really need.
-Mike
Comment
-
Emmanuel Delahaye
Re: Char* to Char*
Jake Thompson a écrit :[color=blue]
> What is the best way to copy a Char* to a Char*?[/color]
No 'Char' in C. I guess you are talking about 'char'.
Use the '=' operator.
char *pa = "hello";
char pb;
pb = pa;
If you meant 'C-string', please, be more specific.
--
A+
Emmanuel Delahaye
Comment
-
Bjørn Augestad
Re: Char* to Char*
Emmanuel Delahaye wrote:[color=blue]
> Jake Thompson a écrit :
>[color=green]
>> What is the best way to copy a Char* to a Char*?[/color]
>
>
> No 'Char' in C. I guess you are talking about 'char'.
>
> Use the '=' operator.
>
> char *pa = "hello";
> char pb;
>[/color]
ITYM char *pb;
Bjørn
Comment
-
Emmanuel Delahaye
Re: Char* to Char*
Bjørn Augestad a écrit :[color=blue][color=green]
>> char *pa = "hello";
>> char pb;
>>[/color]
> ITYM char *pb;[/color]
Yes, thanks.
--
A+
Emmanuel Delahaye
Comment
-
Emmanuel Delahaye
Re: Char* to Char*
Jake Thompson a écrit :[color=blue]
> What is the best way to copy a Char* to a Char*?[/color]
No 'Char' in C. I guess you are talking about 'char'.
Use the '=' operator.
char *pa = "hello";
char *pb;
pb = pa;
If you meant 'C-string', please, be more specific.
--
A+
Emmanuel Delahaye
Comment
-
Chris Hills
Re: Char* to Char*
In article <ln4q4gmo4z.fsf @nuthaus.mib.or g>, Keith Thompson <kst-
u@mib.org> writes[color=blue]
>"Jake Thompson" <readytoride39@ hotmail.com> writes:[color=green]
>> What is the best way to copy a Char* to a Char*?[/color]
>
>That depends on what you mean.
>
>There is no standard type Char; I presume you mean char.[/color]
Aren't you being sensitive in this case? :-)
BTW I have been working on a TC to a standard and using M$ Word is a
right bugger as it auto corrects and capitalises the source code
examples in the text. The other problem is find out where to turn off
all the "help"
--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ chris@phaedsys. org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
Comment
-
Chuck F.
Re: Char* to Char*
Chris Hills wrote:[color=blue]
>[/color]
.... snip ...[color=blue]
>
> BTW I have been working on a TC to a standard and using M$ Word
> is a right bugger as it auto corrects and capitalises the source
> code examples in the text. The other problem is find out where
> to turn off all the "help"[/color]
Even on windoze, you can get good text editors. Try textpad, from
textpad.com.
--
"If you want to post a followup via groups.google.c om, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell. org/google/>
Comment
-
jussij@zeusedit.com
Re: Char* to Char*
> BTW I have been working on a TC to a standard and using M$ Word[color=blue]
> is a right bugger as it auto corrects and capitalises the source
> code examples in the text. The other problem is find out where to
> turn off all the "help"[/color]
Why not uses a programmers editor to write your code. There are
many to choose from.
For example one such choice is the Zeus for Windows IDE:
Note: Zeus is shareware (45 day trial).
It is designed for writing code and has features like configurable
syntax highlighting, project/workspace management, class browsing,
integrated version control etc.
Jussi Jumppanen
Author: Zeus for Windows
Comment
-
Jake Thompson
Re: Char* to Char*
Mike you gave me the answer I need I was just trying to confirm that
you can do a = b
Thanks
Comment
-
M.B
Re: Char* to Char*
jussij@zeusedit .com wrote:[color=blue][color=green]
> > BTW I have been working on a TC to a standard and using M$ Word
> > is a right bugger as it auto corrects and capitalises the source
> > code examples in the text. The other problem is find out where to
> > turn off all the "help"[/color]
>
> Why not uses a programmers editor to write your code. There are
> many to choose from.
>
> For example one such choice is the Zeus for Windows IDE:
>
> http://www.zeusedit.com/features.html
> Note: Zeus is shareware (45 day trial).
>[/color]
Also try gvim.
[color=blue]
> It is designed for writing code and has features like configurable
> syntax highlighting, project/workspace management, class browsing,
> integrated version control etc.
>
> Jussi Jumppanen
> Author: Zeus for Windows[/color]
Comment
-
Mike Wahler
Re: Char* to Char*
"Jake Thompson" <readytoride39@ hotmail.com> wrote in message
news:1136655793 .968250.174460@ f14g2000cwb.goo glegroups.com.. .[color=blue]
> Mike you gave me the answer I need I was just trying to confirm that
> you can do a = b[/color]
You can use the assignment operator (=) to copy
the value of one object to another object whenever
the objects' types are the same or the 'source'
object's type is convertible to the 'destination'
object's type.
-Mike
Comment
-
Jake Thompson
Re: Char* to Char*
Mike you gave me the answer I need I was just trying to confirm that
you can do a = b
Thanks
Comment
-
Richard Bos
Re: Char* to Char*
jussij@spammers edit.com wrote:
[color=blue][color=green]
> > BTW I have been working on a TC to a standard and using M$ Word
> > is a right bugger as it auto corrects and capitalises the source
> > code examples in the text. The other problem is find out where to
> > turn off all the "help"[/color]
>
> Why not uses a programmers editor to write your code.[/color]
Because it is a veritable glutealgy to write the rest of the text in.
BTW: spamming doesn't make your product look any prettier, no matter how
pseudo-targeted.
Richard
Comment
Comment