Path: csiph.com!feeder.erje.net!2.eu.feeder.erje.net!border1.nntp.ams1.giganews.com!nntp.giganews.com!buffer1.nntp.ams1.giganews.com!buffer2.nntp.ams1.giganews.com!nntp.brightview.co.uk!news.brightview.co.uk.POSTED!not-for-mail NNTP-Posting-Date: Wed, 11 Jan 2017 11:20:58 -0600 From: Gareth Owen Newsgroups: comp.lang.c Subject: Re: Correct way of doing string manipulation functions References: Date: Wed, 11 Jan 2017 17:20:58 +0000 Message-ID: <871sw9343p.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) Cancel-Lock: sha1:tSrPhF+KRFBBAN8MbkAAeFoXjlA= MIME-Version: 1.0 Content-Type: text/plain Lines: 26 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-mdNixMajAB/ogBciZbTfkp0JAFBjX2wIcsI152q9jbLXvPqlQiWS0uxYSGdMeQVIzlmjTLaF9uIqqdB!QJDPBGyVEPHXtBxubOxDJyu+yHQnhavDLIw/CQo6xwZI/51zupqxSYvGE3NQz83GNJFYAg== 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: 2150 Xref: csiph.com comp.lang.c:101442 "Fernando D. Bozzo" writes: > Hi all, > > I'm starting at C but have a background on programmming in OOP. > > My question is about string manipulation functions and the > correct/best/good way of doing this in C. Seeing as the technical shortcomings have been addressed I'd just say one extra thing - don't do this in C. String handling is possibly the most error prone part of the language. Even experts have fierce disagreements about the merits of strcpy(), strncpy(), strncpy_s() and the various other ones. The reason for this is that they are all varying degrees of terrible to work with. Manual memory management and null-termination are finicky, and even experienced C-programmer screw up this from time to time. And that's before you even consider the possibility of how Unicode code-points in filenames show up. If these routines are not 100% speed critical (and even if they are), if you have any possibility of writing these particular routines in a language where strings are first class citizens and then copying the bytes into a buffer of char[] for use in C, then I strongly recommend you do so.