Path: csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Program to count words, issues with an if condition within a for loop Date: Wed, 14 Oct 2015 10:23:08 -0700 Organization: None to speak of Lines: 43 Message-ID: References: <1eb5a509-5cd5-46de-9609-98a123ed640c@googlegroups.com> <561a36d9.4647546@news.xs4all.nl> <561e3d8e.7652703@news.xs4all.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="10243"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/sVqGQgQ9TSsVICJcVkTZW" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:vBsLm/wtFFBALSIYt2MDEzffMIQ= sha1:DRuIKrExAXYmIIemkCgRkcSCf/4= Xref: csiph.com comp.lang.c:72859 raltbos@xs4all.nl (Richard Bos) writes: > Keith Thompson wrote: >> raltbos@xs4all.nl (Richard Bos) writes: >> > #include and calling isalpha((unsigned char)c) solves this >> > problem portably. > >> isalpha() is also sensitive to the current locale. In the default "C" >> locale it returns a true result only for the 52 uppercase and lowercase >> letters, but in other locales it can also return a true result for other >> characters -- which are likely to be outside the ranges 'A'..'Z' and >> 'a'..'z'. >> >> So you have to ask yourself: Do you want to match just the 52 Latin >> uppercase and lowercase letters, or do you want to match *all* >> alphabetic characters. > > In theory, yes, though I don't think Alla need worry about that yet. Agreed -- but it's worth keeping in mind that the meaning of a "letter" can go well beyond the 52 uppercase and lowercase letters we usually think about. > In fact, I think most of us don't need to worry about that, ever: the > locale starts in "C", I never change it to another myself unless that > is expressly what I want (which has never happened in serious code > yet), and if a user wants to set the locale to another value through a > system variable or some other method, well, if he's clever enough to > know how to do that he's also clever enough to know what he's getting. Even if the environment configures some odd locale, a C program uses the "C" locale unless it explicitly calls setlocale() or equivalent. On Unix-like systems, setlocale("") sets the locale based on environment variables; the C standard refers to this as "the locale-specific native environment". Without such a call, you can assume that isalpha() will return a true value only for the 52 uppercase and lowercase letters. But it may not be safe to assume that your code will never be used in a program that does call setlocale(). -- 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"