Yes, that's right.
Character literals evaluate to the ascii value of the character. scode == 'A' is exactly the same thing as scode == 65.
Boolean expressions are calculations. When you evaluate 2 * 2 == 4, the result is the number 1. When you say 2 * 3 == 4, the result is the number 0.
In C, when it is evaluating boolean (true or false) types of expression (in 'if', 'while', 'for' etc), the whole expression is true if the answer is not zero, and it is false if the answer is zero.
When evaluating scode == ('r' || 'R'))
this is the order of operations:
- 'r' || 'R' means the following: if 'r' != 0 then the result is 1, else if 'R' != 0 then the result is 1, else the result is zero
so this is how it would break down:
(scode == ('r' || 'R')
simplifies to (scode == (114 || 82))
when it evaluates 114 || 82, it is essentially a calculation that means, if ((114 is not equal to 0) or (82 is not equal to 0)) then the result is 1, else the result is zero.
114 is not equal to zero, which means it is true. Expressions in C use short-circuit evaluation, so using logical OR, there is no need to evaluate the right hand side, because it is OR, 114 is already true. it can (and WILL) skip the other side of …
setting up the boolien the way it is now should tell the compiler the same thing as before shouldn't it? its only realy differant synacticaly right?
Not sure what you mean by "the way it is now" but if you mean like gerard4143's comment, yes that works. I simply explained how the compiler interpreted it the way you originally had it, so you'd know why your original code didn't work.
At first knowing other languages is going to bog you down a little, but soon that's going to turn around and make you able to learn new languages even faster. Programming languages are more alike than they are different, and knowing several sharpens your eye to the kinds of issues that you encountered in this post.
Mike is talking about industrial strength optimal ways to handle it.
A while ago I developed a very simple way of doing it that is not even close to optimal but isn't too bad:
For triangle A B C calculate the vector
N = crossproduct(normalize(B - A), normalize(C - A))
This will give you the surface normal of the plane, N. Make a plane equation P for the plane:
P = -dotproduct(N, A)
Now we can calculate the distance 'start' is from the plane:
startDist = dotproduct(N, start) + Pd
And we can calculate the distance 'end' is from the plane:
endDist = dot(N, end) + Pd
If startDist is not the same sign as endDist then maybe it goes through the plane. If they are the same sign, the line segment between start and end couldn't possibly go through the plane.
Assuming they are different signs, we need to calculate the actual intersection point. We can do that by taking
intersectFrac = startDist / (endDist - startDist)
to calculate how far along the segment between start end end the intersection of the plane lies.
We can normalize the vector
start + (end - start)
and scalar multiply it by intersectFrac to find the exact point where that line intersects the plane.
We can use the surface normal, and each of the three line segments to generate "extruded edges" for the triangles, making …
I think what you are asking is how to reverse engineer the protocol.
Yes, reverse engineering is usually difficult.
One approach is to make the program do known things and watch the data. Repeat the operation and see what changes and what doesn't. Then do something slightly different and see what changes. You will gradually figure out the structure of the data by comparing the data packets to your input. You can gradually narrow down the layout of the packets.
Study operator precedence. I know it's boring as hell, think of it as the same kind of thing as learning your times tables -> boring as hell but great to know once you know. It helps a lot to be able to look at an expression and know what order it will be evaluated in.
What it was doing before was evaluating scode == "p" first. If that was true, the whole expression is true because it's logical or (look up short-circuit evaluation).
If scode is not equal to "p", then it evaluated whether "P" is true, which it always is, because "P" is not a null pointer. A literal string evaluates to the pointer to the first character of the string. Therefore the if condition is always true.