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: Wed, 03 Oct 2018 13:35:27 -0700 Organization: None to speak of Lines: 32 Message-ID: References: <20181003231515.15cfcdd587b8ddd60691ef87@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="8550f27190323af76201106f961d1e2f"; logging-data="8015"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/wdspyXB5nDwB1Ky/IWndp" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:eNX6KK+iwcOsTbZ9a+kEyEhQD9w= sha1:IfSY+h8581dmAJTavwi2BmXfquA= Xref: csiph.com comp.lang.c:136135 Anton Shepelev writes: > TCC's implementations of getc and fgetc seem to collapse > \r\n into \n, and its fputc to expand \n in \r\n. Does > anybody else observe this behavior with TCC (Bart?)? > fputc("\n", file) writes two bytes. Is it normal? TCC using what library? On my Ubuntu system, the tcc compiler uses the same standard library used by gcc and clang. Collapsing \r\n into \n on input, and expanding \n to \r\n on output, is standard behavior for text streams on Windows. Text processing programs only need to worry about it if they're dealing with text files in "foreign" formats. Most programs on Unix-like systems just assume '\n' is the line terminator, and a line containing "\r\n" is just a line of text whose last character before the terminator happens to be '\r'. Usually you'd want to translate text files when transferring them between Windows and Unix systems. If that's not feasible, there are programs such as dos2unix and unix2dos to do the translation for you on the Unix side. (Unfortunately these particular programs don't act like most Unix text filter programs, so it's difficult to use them in pipes.) -- 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"