F
Flash Gordon
P said:Here http://www.le.ac.uk/cc/tutorials/c/ccccstrc.html is a good source
about struct copying.
I would not recommend that start. It recommends doing things which are
generally considered bad style around here, such as casting the return
value of malloc (I can only remember one person on this group with a
good reason to do this, and his reason does not apply to most people)
and using sizeof(type) rather than sizeof *ptr to work out how much
space to allocate. I.e. the web page recommends using, and I quote:
ptr = (*int) malloc(sizeof(int)*N)
The generally recommended style around here is the far simpler and more
maintainable form:
ptr = malloc(N * sizeof *ptr);
Fewer characters to type, remains correct of the type of ptr changes,
and does not hide the required diagnostic if there is no declaration of
malloc in scope.
It also goes on to recommend using #define to create an alias for a
type, which is what the typedef keyword is for, and typedef has
advantages over a #define.
Also, please quote some context when replying so that people know what
you are replying to. It is entirely possible that some people might see
your reply but not the original message. See
http://cfaj.freeshell.org/google/ for more about this problem and how to
post correctly through Google. Also see my sig for a link to a lot
more information on what is considered acceptable in the group and why.