Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: While loop with bool, same issue |
| Date | 2015-10-14 20:44 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <87d1wh9qvr.fsf@bsb.me.uk> (permalink) |
| References | <96769962-2192-444e-a738-01306756e949@googlegroups.com> <mvm3e9$fjs$1@dont-email.me> |
Just an FYI post...
Eric Sosman <esosman@comcast-dot-net.invalid> writes:
> On 10/14/2015 11:59 AM, Alla _ wrote:
>> Hello!
>>
>> I have decided to create a new topic, although
>> with the issue that I have already raised previously
>> (previous one is clear to me now).
>>
>> /** Counting words in a piece of text **/
>>
>> #include <stdio.h>
>> #include <stdbool.h>
>>
>> bool alphabetic (const char c)
>> {
>> if ( (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') )
>> return true;
>> else
>> return false;
>> }
>
> Aside: The `if' is unnecessary. You could simply do
>
> return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
>
> instead. (I mention this mostly because you seem to use this
> silly pattern frequently. It's not "wrong," just silly.)
Sadly, it's from the book.
>> void read_line (char buffer [])
>> {
>> char character;
>> int i = 0;
>>
>> do
>> {
>> character = getchar();
>> buffer[i] = character;
>> i++;
>> }
>> while (character != '\n');
>>
>> buffer[i - 1] = '\0'; // i - 1 because the index character was incremented one extra time inside the loop the last time it was executed
>> }
>
> Aside: This is, more or less, a re-implementation of the
> COMPLETELY UNSAFE gets() function, a function SO BAD that it has
> been removed from the latest C Standard. (I say "more or less"
> because there are errors: See question 12.1 on the comp.lang.c
> FAQ page at <http://www.c-faq.com/> for one of them, and you'll
> learn about the other if you ever type your system's end-of-input
> keystroke -- maybe CTRL-D or CTRL-Z -- at the keyboard.)
Again, it's from the textbook though with a slight name change and a
comment added.
Dorothy Parker comes to mind... "This is not a book to be cast aside
lightly. It should be thrown with great force." (paraphrased)
No book on C should be cavalier about buffer overruns.
<snip>
--
Ben.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
While loop with bool, same issue Alla _ <modelling.data@gmail.com> - 2015-10-14 08:59 -0700
Re: While loop with bool, same issue Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-10-14 13:31 -0400
Re: While loop with bool, same issue August Karlstrom <fusionfile@gmail.com> - 2015-10-14 20:11 +0200
Re: While loop with bool, same issue Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-10-14 14:26 -0400
Re: While loop with bool, same issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-14 20:44 +0100
Re: While loop with bool, same issue Siri Cruz <chine.bleu@yahoo.com> - 2015-10-14 10:45 -0700
Re: While loop with bool, same issue Keith Thompson <kst-u@mib.org> - 2015-10-14 13:15 -0700
Re: While loop with bool, same issue Keith Thompson <kst-u@mib.org> - 2015-10-14 11:42 -0700
Re: While loop with bool, same issue Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-10-15 08:20 +0000
csiph-web