Yes i thought about it. The thing is that im gonna have a lot of cases, like 20 or more.
Now would it be possible to put them in a file apart like #include "conditions.h" and
make a reference to if() like: if ( conditions.h)
No, you should not do that. I believe you do not have so many cases, actually. What do you think these cases are?
In this case if i declare it in the while loop, i must declare it two times,
thats why i think its maybe better to declare it outside, only once.
Do not worry about that: the compiler can optimise it for you.
Otherwise with your condition it works perfectly well.
Wich is comletely incomprehensible because
These two are exactly the same :
Your expression:
Code:
(str1[pos-3] != ' ' && str1[pos-2] != 'a' ) && (str1[pos-4] != ' ' && str1[pos-3] != 'a' && str1[pos-2] != 'n')
is equivalent to:
Code:
(!(str1[pos-3] == ' ') && !(str1[pos-2] == 'a')) && (!(str1[pos-4] == ' ') && !(str1[pos-3] == 'a') && !(str1[pos-2] == 'n'))
as you have pointed out. Now, using De Morgan's rule, we get:
Code:
!(str1[pos-3] == ' ' || str1[pos-2] == 'a') && !(str1[pos-4] == ' ' || str1[pos-3] == 'a' || str1[pos-2] == 'n')
which is obviously not the same as my suggestion:
Code:
!(str1[pos-3] == ' ' && str1[pos-2] == 'a') && !(str1[pos-4] == ' ' && str1[pos-3] == 'a' && str1[pos-2] == 'n')
which is equivalent to:
Code:
!((str1[pos-3] == ' ' && str1[pos-2] == 'a') || (str1[pos-4] == ' ' && str1[pos-3] == 'a' && str1[pos-2] == 'n'))
it messes up so much the memory that even if i change it with yours, the code wont work anymore.
What do you mean?