strcpy vs memcpy

I

Ian Collins

James said:
It's part of a TR being processed by the C standards committee,
which means that it is, or will be, an optional part of standard
C. Certainly not a Microsoftism. From a quality of
implementation point of view, one would expect to find it in any
up to date C compiler.

Really? Considering Microsoft doesn't even support C99, that's a bit rich!
 
N

Nick Keighley

And any sane programmer will prefer strncpy() over strcpy() for safety
reason unless you do not know the size of the destination.

nonsense! strncpy() has all sorts of odd behaviour
 
N

Nick Keighley

when we should use strcpy( )  and when memcpy( ) ? is it w.r.t. to
Data Type

more the semantics (meaning) of the data. Use strcpy() to copy
a C-string and memcpy() to copy a block of memory of known size.

In a C++ program (and you are posting on comp.lang.c++) you should
only very rarely be using C-strings. Use C++ strings and just assign
them.
 
J

James Kanze

Really? Considering Microsoft doesn't even support C99,
that's a bit rich!

In what sense. It is surprising that they support this, I
agree. But it's very much a part of C, and it's even more
surprising that serious C compilers don't support it. (On the
other hand, there are some serious C++ compilers which don't
support export, and that's fully a part of the standard. In the
end, I gather that most compiler vendors don't really give a
damn about the standard, and just support whatever they feel
like.)
 
N

Nick Keighley

man strtok:

BUGS
       Avoid using these functions.  If you do use them, note that:

              These functions modify their first argument.

              These functions cannot be used on constant strings.

those aren't what I'd call "bugs". They are simply what the function
does.

              The identity of the delimiting character

what about it?

Actually what i don't like about strtok() is how it handles empty
fields

red,blue,,green
 
J

James Kanze

Where is it defined as part of C?

It will be defined in a TR.
Not in the C99 standard or the latest C1x draft.

TR's aren't directly incorporated in the standard; they're
optional extensions. But such extensions are as much a part of
C as things like tr::array are a part of C++.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,159
Messages
2,570,879
Members
47,414
Latest member
GayleWedel

Latest Threads

Top