Quote:
Originally Posted by Chaos in a Can
When I used a printf with about seven %d's, something that should have shown up as a 1 or 0 was printing about 150.
It wasn't until I tried using separate printf's for each value that I found that it had either swapped or skipped some of the values and was printing an input from the joystick where it should have been printing a digital input.
|
This is a symptom of not matching the format information with the size of the variable to be printed.
%d wants an
int. If you instead give it a
char, it will also grab the next byte of data to go with it, and everything will be misaligned from that point on. It's a good idea to get in the habit of
always explicitly casting your
%d-printed variables as
(int).