Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #6936

Re: Query abt union

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!selfless.tophat.at!news.glorb.com!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail
NNTP-Posting-Date Sat, 25 Jun 2011 14:30:30 -0500
Message-ID <4E063758.5934@mindspring.com> (permalink)
Date Sat, 25 Jun 2011 15:30:32 -0400
From pete <pfiland@mindspring.com>
Reply-To pfiland@mindspring.com
Organization PF
X-Mailer Mozilla 3.04Gold (WinNT; I)
MIME-Version 1.0
Newsgroups comp.lang.c
Subject Re: Query abt union
References <iu06d5$cnu$1@speranza.aioe.org> <YnPMp.17322$PA5.15790@newsfe01.iad> <iu0g7a$b58$1@dont-email.me> <lnzkl8dqt2.fsf@nuthaus.mib.org> <iu2un1$ne7$1@nnrp.ngi.it> <4E05F19D.6221@mindspring.com>
Content-Type text/plain; charset=us-ascii
Content-Transfer-Encoding 7bit
Lines 31
X-Usenet-Provider http://www.giganews.com
NNTP-Posting-Host 4.154.221.249
X-Trace sv3-jZBiajSwy0yuQRaru/11b8twnzOM4ABE4zxFA2mGzPOpphJHUpzMbj8KXwlfZKH03BAVUZjdcSg9Tec!EuILwsHRSSBISP+2p9Dg+NzUPXaIxixBJk9iJ+sQmWpoA/g1wdLxoxDh9F1NoH+54FdkacYENLcn!m9TDXGVDTLE=
X-Abuse-and-DMCA-Info Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info Otherwise we will be unable to process your complaint properly
X-Postfilter 1.3.40
X-Original-Bytes 1958
Xref x330-a1.tempe.blueboxinc.net comp.lang.c:6936

Show key headers only | View raw


pete wrote:
> 
> pozz wrote:
> 
> > So I think strncpy() is good to avoid this bad situations:
> >
> >    char mystring[10];
> >    void mystrcpy(const char *arg) {
> >      strncpy(mystring, arg, sizeof(mystring) - 1);
> >      mystring[sizeof(mystring) - 1] = '\0';
> >    }
> >
> > What is wrong with this?
> 
> Why wouldn't you use memcpy instead of strncpy
> in the above code?
> 
> memcpy is the simpler of the two functions.
> 
> The extra features which distiguish strncpy from memcpy
> are only useful in the above code
> if you really want mystring
> to be padded out to the end with null bytes.

I take that back.
It would be more complicated with memcpy.
You would have to provide code to prevent memcpy
from reading beyond a short string.

-- 
pete

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Query abt union "sumit.sharma" <nospam@nospam.com> - 2011-06-23 20:07 +0000
  Re: Query abt union Ben Pfaff <blp@cs.stanford.edu> - 2011-06-23 13:18 -0700
  Re: Query abt union Shao Miller <sha0.miller@gmail.com> - 2011-06-23 17:20 -0500
    Re: Query abt union James Waldby <not@valid.invalid> - 2011-06-24 17:34 +0000
      Re: Query abt union Shao Miller <sha0.miller@gmail.com> - 2011-06-24 14:42 -0400
        Re: Query abt union James Waldby <not@valid.invalid> - 2011-06-24 21:13 +0000
          Re: Query abt union Shao Miller <sha0.miller@gmail.com> - 2011-06-26 14:08 -0500
            Re: Query abt union James Waldby <not@valid.invalid> - 2011-06-27 05:13 +0000
  Re: Query abt union John Gordon <gordon@panix.com> - 2011-06-23 22:27 +0000
  Re: Query abt union Lew Pitcher <lpitcher@teksavvy.com> - 2011-06-23 18:47 -0400
    Re: Query abt union Shao Miller <sha0.miller@gmail.com> - 2011-06-23 17:54 -0500
      Re: Query abt union Keith Thompson <kst-u@mib.org> - 2011-06-23 17:19 -0700
        Re: Query abt union Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2011-06-23 22:12 -0600
          Re: Query abt union Keith Thompson <kst-u@mib.org> - 2011-06-23 22:32 -0700
            Re: Query abt union Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2011-06-24 08:51 -0600
              Re: Query abt union Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-06-24 16:30 +0100
          Re: Query abt union pete <pfiland@mindspring.com> - 2011-06-24 12:46 -0400
            Re: Query abt union Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2011-06-24 16:18 -0600
        Re: Query abt union pozz <pozzugno@gmail.com> - 2011-06-24 23:14 +0200
          Re: Query abt union John Gordon <gordon@panix.com> - 2011-06-24 21:37 +0000
            Re: Query abt union Shao Miller <sha0.miller@gmail.com> - 2011-06-26 14:28 -0500
          Re: Query abt union Keith Thompson <kst-u@mib.org> - 2011-06-24 14:56 -0700
            Re: Query abt union Edward Rutherford <edward.p.rutherford79@REMOVETHIS.gmail.com> - 2011-06-24 22:10 +0000
              Re: Query abt union Keith Thompson <kst-u@mib.org> - 2011-06-24 15:41 -0700
          Re: Query abt union pete <pfiland@mindspring.com> - 2011-06-25 10:33 -0400
            Re: Query abt union pete <pfiland@mindspring.com> - 2011-06-25 15:30 -0400
          Re: Query abt union Shao Miller <sha0.miller@gmail.com> - 2011-06-26 14:12 -0500
    Re: Query abt union Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2011-06-23 17:13 -0600

csiph-web