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
Need sharp criticism on my code.
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="Ben Bacarisse, post: 4066519"] Do you know De Morgan's laws? They are very helpful in cases like this: !(C1 && C2 && C3...) => !C1 || !C2 || !C3... !(C1 || C2 || C3...) => !C1 && !C2 && !C3... Just to check that we both came to the same conclusion, here is your condition with the function call replaced by simple identifiers: fgets && !(cDef && !(s_case1 || s_case2_1 || s_case2_2 || s_case3)) De Morgan's laws allow you to re-write the second part of the && as: fgets && (!cDef || !!(s_case1 || s_case2_1 || s_case2_2 || s_case3)) and we can (in this situation) replace !!C1 with C1: fgets && (!cDef || (s_case1 || s_case2_1 || s_case2_2 || s_case3)) and remove the now redundant brackets: fgets && (!cDef || s_case1 || s_case2_1 || s_case2_2 || s_case3) which is (fortunately!) the condition I suggested. Probably, though my version is a little simpler. The "exceptions" should really be in an array, of course. Then you could write: while (fgets(buff, 500+1, fp) && !strstr(buff, cDefinition) && !match_any(buff, exceptions)) {...} One day, this might even have to become: while (fgets(buff, 500+1, fp) && match_any(buff, definitons) && !match_any(buff, exceptions)) {...} [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C Programming
Need sharp criticism on my code.
Top