Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Counting lines of a file Date: Thu, 04 Oct 2018 15:53:26 -0700 Organization: None to speak of Lines: 39 Message-ID: References: <7q1tD.728075$PJ7.722912@fx01.am4> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: reader02.eternal-september.org; posting-host="af9ae907079c17818bc7064dc388259f"; logging-data="9606"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX185tLWRWqcV4dKH2UIG+YfS" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:IpKm8M3SIfvdZyTW1GuDQ5wM+nc= sha1:b60MybCByFxgqj90uH6R4AJOits= Xref: csiph.com comp.lang.c:136234 Bart writes: > On 04/10/2018 21:00, David Brown wrote: [...] >> I have never thought is was a good idea to have newlines in filenames, >> but what I wrote suggested that I thought other people used them or >> thought it was a good idea.  It is not /very/ difficult to make >> filenames with newlines in a file manager in Linux - but it is >> inconvenient enough that it is unlikely people would do it. > > It makes some things more difficult. Yes. > For the example, the ostensibly > simple task of storing a list of filenames in a file. Similar to the > challenge in the OP's program to read a list of filenames from stdin. > > If you take the simple approach of having one per line, how do you > represent a name with an embedded newline? You don't -- so either don't store them that way, or take care that you don't have any files whose names contain newlines, or acknowledge that your format will fail if any files have names containing newlines. But it's essentially a solved problem. The existing tools on most Linux-based systems are capable of handling file names with newlines (or any other arbitrary characters) with just a little extra effort, using nul-delimited names as supported by find, xargs, wc, and probably other tools as well. But by all means feel free not to use them. [...] -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"