Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C Programming
what is the difference between these statement
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Dr Nick, post: 5021682"] The second statement should do something - because it should always be true. Think about it - if c is a space it isn't an newline or a tab, and if it's a newline it isn't a space or a tab, and if it's an 'x' it isn't a space, or a newline, or a tab. You need && in there - you need all the conditions to be true, not just one of them. 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} and if(!isspace((unsigned char)c) { increase no of word} 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). They make it slightly less elegant, but it's still tidier and will be familiar to experienced programmers. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C Programming
what is the difference between these statement
Top