| | |
Print_Zero Function
![]() |
•
•
Join Date: Jan 2005
Posts: 14
Reputation:
Solved Threads: 0
I have a Distance Structure that includes Miles, Feet, and Inches. The user inputs these amounts 3 digits for miles, 4 digits for feet and 2 digits for inches. Not all of the time the user will input the full number of digits, when the user doesn't input the full number of digits I need to back fill the numbers with zero's for display. Like 97 for miles I would display is 097. The zero would be added to the user input by a call to the Print_zero function. I need some ideas on how to incorporate the back fill zero into a function. Thanks.
•
•
Join Date: Nov 2004
Posts: 108
Reputation:
Solved Threads: 3
psuedo code:
C Syntax (Toggle Plain Text)
if miles <100 print 0 and miles if feet < 1000 print 0 and feet if inches < 10 print 0 and inches
Join me on IRC:
Server: irc.daniweb.com
Channel: #C++
Chat Via:
http://daniweb.com/chat/minichat.php
or
Your favorite IRC client.
Server: irc.daniweb.com
Channel: #C++
Chat Via:
http://daniweb.com/chat/minichat.php
or
Your favorite IRC client.
Test drive this to get another hint:
[php]// pad with zero using sprintf()
#include <stdio.h>
int main()
{
int mile; //, foot, inch;
char *pad;
printf("Enter miles: ");
scanf("%d", &mile);
fflush(stdin); // flush input stream
// pad with max 3 zeros (this is a zero not an ohh)
sprintf(pad,"%03d",num);
printf("Zero padded = %s miles\n",pad);
getchar(); // wait
return 0;
}
[/php]
[php]// pad with zero using sprintf()
#include <stdio.h>
int main()
{
int mile; //, foot, inch;
char *pad;
printf("Enter miles: ");
scanf("%d", &mile);
fflush(stdin); // flush input stream
// pad with max 3 zeros (this is a zero not an ohh)
sprintf(pad,"%03d",num);
printf("Zero padded = %s miles\n",pad);
getchar(); // wait
return 0;
}
[/php]
May 'the Google' be with you!
•
•
•
•
Originally Posted by vegaseat
Test drive this to get another hint:
[php]// pad with zero using sprintf()
#include <stdio.h>
int main()
{
int mile; //, foot, inch;
char *pad;
printf("Enter miles: ");
scanf("%d", &mile);
fflush(stdin); // flush input stream
// pad with max 3 zeros (this is a zero not an ohh)
sprintf(pad,"%03d",num);
printf("Zero padded = %s miles\n",pad);
getchar(); // wait
return 0;
}
[/php]
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
![]() |
Similar Threads
- ASP Replace Function.... (ASP)
- missing function header (C++)
- Function that returns void (C++)
Other Threads in the C Forum
- Previous Thread: Can't Display These Topics By Sort?!!
- Next Thread: Help for graphics in C
| Thread Tools | Search this Thread |
#include * ansi api array arrays asterisks binarysearch calculate centimeter changingto char character convert copyanyfile copyimagefile copypdffile creafecopyofanytypeoffileinc createcopyoffile createprocess() database dynamic execv fflush fgets file floatingpointvalidation fork forloop frequency function getlogicaldrivestrin givemetehcodez grade graphics gtkwinlinux histogram homework i/o inches include infiniteloop input interest intmain() iso keyboard km license linked linkedlist linux list looping loopinsideloop. lowest matrix microsoft mysql oddnumber open opendocumentformat openwebfoundation pdf pointer posix power program programming pyramidusingturboccodes radix read recursion recv recvblocked reversing scanf scheduling segmentationfault send sequential shape single socket socketprogramming stack standard strchr string suggestions test threads turboc unix urboc user variable whythiscodecausesegmentationfault win32api windowsapi






