Study up on printf(), particularly the width format specifier. Apply this to sprintf() within your function. Most help files that come with the compilers should give you all the details.
vegaseat
DaniWeb's Hypocrite
5,986 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
Test drive this to get another hint:
[php]// pad with zero using sprintf()
#include
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]
vegaseat
DaniWeb's Hypocrite
5,986 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
Test drive this to get another hint:
[php]// pad with zero using sprintf()
#include
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]
Let's playCount the Undefined Behavior with that. ;)
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314