can we specify variable field width in a scanf() format
string? if possible how in c language?



can we specify variable field width in a scanf() format string? if possible how in c language?..

Answer / deepedra kushwaha

You can't specify a variable field with a fixed format
string, but you can get around this by making the format
string variable:

int width;
char format[20]; /* or whatever size is appropriate */
int value;

...
sprintf(format, "%%%dd", width); /* generates a string like
"%5d" */
scanf(format, &value);

The only drawback to this method, other than requiring two
statements, is that the compiler can't do a sanity check on
the arguments to scanf like it can when the format is a
string constant.

Read more:
http://wiki.answers.com/Q/Can_you_specify_variable_field_width_in_a_scanf_format_string_If_possible_how#ixzz1bSMgbeUL

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More Engineering AllOther Interview Questions

How to configure gigabit port in 2950

3 Answers   Cisco,


hello sir,pls fdorward previous group-I exam papers .....

0 Answers   APPSC,


Draw the diagram showing the function stack, illustrating the variables that were pushed on the stack at the point when function f2 has been introduced . type def struct { double x,double y} point; } main( int argc, char *arg[3]) { double a; int b,c; f1(a,b); } f1(double x, int y) {point p; stack int n; f2(p,x,y) } f2(point p, double angle) { int i,j,k,int max;

0 Answers   Geometric Software,


difference between a for loop and a while loop? what are its uses in c language?

0 Answers  


THESE POSTS ARE FOR THE DURATION OF FIVE YEARS. AFTER COMPLETION OF FIVE YEARS, THE PERSONNEL POSTED AGAINST THESE POSTS ARE LIKELY TO BE CONTINUED IN NIC. CAN Any body say that what it will be happened after 5 years? does they through us out from NIC? Is it a temporary job of 5 years is the probation period?

0 Answers   NIC,






Describe VCO?

1 Answers  


java support which type of polymorphism??runtym or compile tym or both??

1 Answers   Infosys,


explain software engineering practices

0 Answers  


why unix commands simpler rather than complex task

0 Answers  


how will u recieve idoc

0 Answers   HCL,


I want to know the relation between GI pipe ID, water flow rate in lpm, static head and friction head losses, motor kw for that flow etc.

1 Answers  


Which of the following statements are true about constructors and methods? 1)A constructor has it's own name, a return type and is invoked using the new operator. 2)A function has it's own name, a return type and is invoked using the dot operator. 3)A constructor has the name of the class, no return type and is invoked using the new operator.

4 Answers   CSE,


Categories
  • Civil Engineering Interview Questions Civil Engineering (5085)
  • Mechanical Engineering Interview Questions Mechanical Engineering (4451)
  • Electrical Engineering Interview Questions Electrical Engineering (16632)
  • Electronics Communications Interview Questions Electronics Communications (3918)
  • Chemical Engineering Interview Questions Chemical Engineering (1095)
  • Aeronautical Engineering Interview Questions Aeronautical Engineering (239)
  • Bio Engineering Interview Questions Bio Engineering (96)
  • Metallurgy Interview Questions Metallurgy (361)
  • Industrial Engineering Interview Questions Industrial Engineering (259)
  • Instrumentation Interview Questions Instrumentation (3014)
  • Automobile Engineering Interview Questions Automobile Engineering (332)
  • Mechatronics Engineering Interview Questions Mechatronics Engineering (97)
  • Marine Engineering Interview Questions Marine Engineering (124)
  • Power Plant Engineering Interview Questions Power Plant Engineering (172)
  • Textile Engineering Interview Questions Textile Engineering (575)
  • Production Engineering Interview Questions Production Engineering (25)
  • Satellite Systems Engineering Interview Questions Satellite Systems Engineering (106)
  • Engineering AllOther Interview Questions Engineering AllOther (1379)