Go to Post Changing lives as a key volunteer is not a right reserved for the "elite" among us anymore. - HurdFIRST [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #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.
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Tether for new EduBot Controller gburlison Programming 9 18-12-2003 17:53
pwm 13-15 wayne 05 Programming 2 04-10-2003 12:08
PWM and burning out motors patrickrd Technical Discussion 7 19-06-2003 15:30
Hints For Rookie Programmers Noah Programming 30 20-02-2003 20:07
relay and pwm outputs nick_champ_2 Electrical 1 31-01-2003 13:08


All times are GMT -5. The time now is 03:15.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi