Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!mailrus!purdue!decwrl!labrea!Portia!jrll From: jrll@Portia.Stanford.EDU (john ralls) Newsgroups: comp.lang.c Subject: Re: Simple C Question (was: down) Summary: My way of counting \n as two chars Message-ID: <4385@Portia.Stanford.EDU> Date: 14 Dec 88 22:05:05 GMT References: <192@broadway.UUCP> Reply-To: jrll@Portia.stanford.edu (john ralls) Organization: Stanford University Lines: 18 In article <192@broadway.UUCP> furlani@broadway.UUCP (John L. Furlani) writes: > >In article , slores%gables.span@umigw.miami.edu (Stanislaw L. Olejniczak) writes: >> PLEASE don't flame for posting too simple a question. I think the following >> The purpose is to count characters in a file. Each time a newline is > > if (c == '\r') chcnt++; True, this will count carriage returns and not newlines. In fact, it will count only carriage returns, which isn't what he had in mind. He wanted to count all characters, counting newlines as two characters (ie, cr/lf). Two ways to do it: if (c == '\n') chcnt +=2; else chcnt++; or for those who like the ternary operator (like me): c == '\n' ? chcnt +=2 : chcnt++; John