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

What is OHNS Material and can anybody explain the Chemical & Physical Properties of Same. Which Technical Standard Book shows this Specification. Why can't we use En series instead of OHNS. Where it is specifically Used.

3 Answers   Advanced Bolting Solutions,


As you achieve greater success with the company after some years, Will you like to be a shareholder in our company?

1 Answers   GE,


hi my name is ashok i have 55 per and 2 backlogs and one year left may i get above 60 pr

0 Answers  


What is HPLC ? and define it.

0 Answers  


what is 16 bit processor and what is 32 bit processor?how can we differentiate and identify or find that ?How they access data?

0 Answers   Excel,






which collection enforces type safety?

0 Answers  


What is the meaning of "co relation" and what is the value of "co relation" in the performance testing environment.

0 Answers  


why java take 2 byte for charecter???

1 Answers   MAHINDRA,


why unix commands simpler rather than complex task

0 Answers  


what is difference between shell commands and shell scripting commands or both r same?

0 Answers  


which is the proper pipe for salt water line

1 Answers   Robinson,


find the net id and host id of the following IPV4 117.34.3.8 and 132.57.8.6

0 Answers   Green University of Bangladesh,


Categories
  • Civil Engineering Interview Questions Civil Engineering (5085)
  • Mechanical Engineering Interview Questions Mechanical Engineering (4452)
  • Electrical Engineering Interview Questions Electrical Engineering (16638)
  • 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)