View Single Post
  #11   Spotlight this post!  
Unread 30-01-2008, 07:54
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Problem with printf()

Quote:
Originally Posted by Chaos in a Can View Post
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).