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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

How I can write a java program output the following 1+2+4+7+......N

1667


how the parting surface is selected in injection mould

1647


Why is using C language

1801


what is need of interface. what is the diff b/w interface and abstract class

1620


what are the reseach done by itc brfore launching e-copal

1637


i am going to give interview for the post of ibps po..so there is a question in my mind which is "Being an electonics and communication engineer how can you help in banks, I mean whats the application of your education in banking."

1911


c# code, vb.net code language parity refers to what?

3247


is it possible to get u.s visa with 55% in b-tech and 15 backlogs

1751


What is Mointer in Operating System?

1487


what are the various login options used in loadrunner tool to make a application performance testing

1572


Which is better field cad/cam in mechanical or film editing/animation is better salary wise?

1629


How we calculate steam turbine governor linkage assembly?

1731


CSS corp interview process and placement papers

1749


is the used fire extinguisher fall under Hazardous waste material?

1650


can you provide me uniken pvt ltd. technical interview question and answer?

2829