View Single Post
  #1 (permalink)  
Old 06-14-2008, 07:18 AM
payam.a payam.a is offline
Newbie
 
Join Date: Jun 2008
Posts: 12
Credits: 0
Rep Power: 0
payam.a is on a distinguished road
Default a problem in C pre specifire

hello my dear friends;
I was reading part of a C code that i confronted with a question that i have copied and pasted for you.
my problem is in line 10 & 13 below. that I have mentioned them below.
what does a * do in this program? it has just one specifier like %d or %f but in front of it has two value. what has happened to the next one?
thanks if you answer me.


Code:
/* varwid.c -- uses variable-width output field */

#include <stdio.h>

int main(void)

{

    unsigned width, precision;

    int number = 256;

    double weight = 242.5;



    printf("What field width?\n");

    scanf("%d", &width);

   10     printf("The number is:%*d:\n", width, number);

    printf("Now enter a width and a precision:\n");

    scanf("%d %d", &width, &precision);

  13      printf("Weight = %*.*f\n", width, precision, weight);

    printf("Done!\n");



    return 0;

}
this is it's output
What field width?

6

The number is : 256:

Now enter a width and a precision:

8 3

Weight = 242.500

Done!

Last edited by WingedPanther; 06-15-2008 at 08:22 AM. Reason: add code tags
Reply With Quote

Sponsored Links