View Single Post
  #13   Spotlight this post!  
Unread 15-01-2004, 10:34
Mike Soukup's Avatar
Mike Soukup Mike Soukup is offline
Software guy
FRC #0111 (Wildstang)
Team Role: Engineer
 
Join Date: May 2001
Rookie Year: 1996
Location: Schaumburg, IL
Posts: 797
Mike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond repute
Re: Trouble with pwm outputs

Quote:
Originally Posted by Just3D
You are correct. The & symbol denotes the address of a variable, passing this information to the printf function. Printf requires a pointer, which is why the & is needed.
So that's why printf hasn't worked for me the past 8 years, I should have tried adding an '&' and would have all been good

Please do NOT answer questions if you do not know the answer. Giving people an authoritative answer when you don't really know what you're talking about is bad and is one of the huge downfalls of CD.

printf does not require the address of the variable unless you want to print out the address. It takes the variable itself. Do not use an '&'.

Code:
int a;
a = 5;
printf("%d %d\n", a, &a);
will print
Code:
5 2293484
Notice that the first one printed the value of a and the second printed the address of a (address will vary).

Also, as gwross (someone you should always listen to) said, you need to cast your variables to an integer to get them to print correctly with this implementation of printf:
Code:
printf("%d\n", (int)a);

Quote:
As for the digits between the % and the 'd', lpramo55 was right in saying the number controls the number of digits output. If you write a 3, it will display 3 digits, adding zeroes as necessary. This also works with decimal places.
Also not correct.
Code:
int a;
a = 5;
printf("%3d\n%03d\n", a, a);
will print out:
Code:
  5
005
The zeros will only be printed out if you have a '0' before the number.