Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Dr Nick <3-nospam@temporary-address.org.uk> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: what is the difference between these statement |
| Date | 2012-05-06 19:23 +0100 |
| Message-ID | <87mx5lxj72.fsf@temporary-address.org.uk> (permalink) |
| References | <05e9a565-918a-4058-a323-7cdaa921ab41@qg3g2000pbc.googlegroups.com> <87vck9xtkp.fsf@temporary-address.org.uk> <0.43422b72d7ed17378938.20120506183234BST.87sjfdgqq5.fsf@bsb.me.uk> |
Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
> Dr Nick <3-nospam@temporary-address.org.uk> writes:
> <snip>
>> There is a useful function (in ctypes.h) for this - called "isspace".
>> So you can replace your pieces of code with:
>> #include <ctypes.h>
>> ...
>> if(isspace((unsigned char)c) {then go to next character }
>> else ( increase no of word}
>
> I don't think K&R have introduced these by the time this exercise is
> set. No reason not to mention them, of course, but you then have to
> explain the (unsigned char)c cast:
At this time I didn't know it was from K&R.
> <snip>
>> The "(unsigned char)" bits are in for technical reasons; they prevent
>> the isspace function doing something silly if you pass an unusual value
>> to them (like and end of file, or perhaps certain accented characters
>> depending on various other things).
>
> The OP has now posted their full code and they correctly have
>
> int c;
> ...
> ... c = getchar() ...
>
> so the cast is not needed. In fact, if they changed the code so that
> EOF might to be passed to a ctype function, the cast makes the code
> wrong! I realise you could not know that c was an int set by getchar()
> at the time you posted, but there was always a risk such advice could be
> wrong or confusing.
>
> <snip>
OK. I'll go away now. Sorry for trying to be helpful but not being
telepathic.
--
Online waterways route planner | http://canalplan.eu
Plan trips, see photos, check facilities | http://canalplan.org.uk
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
what is the difference between these statement ashu <ashishmourya21@gmail.com> - 2012-05-06 04:11 -0700
Re: what is the difference between these statement Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-05-06 12:29 +0100
Re: what is the difference between these statement ashu <ashishmourya21@gmail.com> - 2012-05-06 07:56 -0700
Re: what is the difference between these statement ashu <ashishmourya21@gmail.com> - 2012-05-06 08:01 -0700
Re: what is the difference between these statement Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-05-06 18:54 +0100
Re: what is the difference between these statement Dr Nick <3-nospam@temporary-address.org.uk> - 2012-05-06 15:39 +0100
Re: what is the difference between these statement Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-05-06 18:32 +0100
Re: what is the difference between these statement Dr Nick <3-nospam@temporary-address.org.uk> - 2012-05-06 19:23 +0100
Re: what is the difference between these statement Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-05-06 22:52 +0100
Re: what is the difference between these statement Dr Nick <3-nospam@temporary-address.org.uk> - 2012-05-07 08:08 +0100
Re: what is the difference between these statement Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-05-07 12:44 +0100
Re: what is the difference between these statement Dr Nick <3-nospam@temporary-address.org.uk> - 2012-05-09 06:54 +0100
Re: what is the difference between these statement James Kuyper <jameskuyper@verizon.net> - 2012-05-09 07:46 -0400
Re: what is the difference between these statement Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-05-09 15:32 +0100
Re: what is the difference between these statement Tim Rentsch <txr@alumni.caltech.edu> - 2012-05-09 12:02 -0700
Re: what is the difference between these statement jgk@panix.com (Joe keane) - 2012-05-10 17:46 +0000
Re: what is the difference between these statement Keith Thompson <kst-u@mib.org> - 2012-05-10 11:47 -0700
Re: what is the difference between these statement Tim Rentsch <txr@alumni.caltech.edu> - 2012-05-11 08:55 -0700
Re: what is the difference between these statement jgk@panix.com (Joe keane) - 2012-05-13 20:09 +0000
Re: what is the difference between these statement Kaz Kylheku <kaz@kylheku.com> - 2012-05-13 23:24 +0000
Re: what is the difference between these statement Tim Rentsch <txr@alumni.caltech.edu> - 2012-05-14 11:46 -0700
csiph-web