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
What is frog testing? What is cone model?
I want to join for load runner training..please suggest me which is the best institute for load runner training in bangalore?
write a pgm to accept an array of names & name & check whether the name is present in the array. return the count of occurance. use following array as input; {"Dave","Ann","dev","merry"}
which is better php,asp.net,jsp? and why?
how will u recieve idoc
what is the concept of c++ class
can u tell me what are the subjects involved in group I and II and how i prepare for the exam
how i run the assembly language code
what are the differences between one dimensional ram and two dimensional ram?
What is Symbian.?
what are the various technique used for inter process communication?
what is the basic need for tech..test?
what is the heat insulation material is adaptable for a flue gas duct that carries waste heat from brick kiln to brick drier and what temperature is required to maintain at the tunnel to dry adobe bricks adequately
What experience have you had in writing technical materials?
What does "stdafx"header file do?