From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1d321b3a6b8bcab2 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1995-01-24 23:27:29 PST Path: nntp.gmd.de!newsserver.jvnc.net!nntpserver.pppl.gov!princeton!udel!gatech!swrinde!pipex!uunet!gwu.edu!seas.gwu.edu!dobrien From: dobrien@seas.gwu.edu (David O'Brien) Newsgroups: comp.lang.ada Subject: Re: "Subtract C, add Ada" Date: 25 Jan 1995 07:27:29 GMT Organization: George Washington University Message-ID: <3g4uh1$g07@cronkite.seas.gwu.edu> References: <3fo2ot$su2@miranda.gmrc.gecm.com> <1995Jan23.154631.6702@sei.cmu.edu> <3g32li$5jd@Starbase.NeoSoft.COM> NNTP-Posting-Host: 128.164.9.3 X-Newsreader: TIN [version 1.2 PL2] Date: 1995-01-25T07:27:29+00:00 List-Id: Samuel Mize (smize@Starbase.NeoSoft.COM) wrote: : In article <1995Jan23.154631.6702@sei.cmu.edu>, : Robert Firth wrote: : >In article <3fo2ot$su2@miranda.gmrc.gecm.com> bill@valiant (R.A.L Williams) writes: : > : ... : >> 1. It allows your code to be more compact. : > : >> NB DONT confuse compactness with poor layout! I find that, for example: : >> : >> while ((c = getchar()) == ' ') : >> { : >> /* count spaces */ : >> } : >> : This bit of code is based on the assumption that there is a null at : the end of your string -- oh, but this is a file read. C guys: : does C return a null if you getchar at EOF? Or is this a misplaced : array idiom? This code is *not* based on the assumption that there is a ASCII NUL at the end of the string. There is nothing here that implies a string. A string being a series of characters terminated by an ASCII NUL character. Nor is this a file read. getchar reads from the standard input. This would be interactive input unless the input has been redirected to a file. C (what I believe you are actually asking is does getchar return a NUL at EOF), returns the EOF "character" at EOF. If the above code was reading from a file, the loop would terminate at EOF since EOF is not the same value as a space character. So the code fragment is still ok with redirected input. -- David O'Brien (dobrien@seas.gwu.edu)