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
hi, i applied for AIRPORTS AUTHORITY OF INDIA for the post of AIR TRAFFIC CONTROLLER(ATC)..so plz send me the sample questions to my id...88arun@gmail.com
I want to prepare for PSU's bt i dont know how many PSU's are open for computer science students and what is the competition level for these. So if anybody knows this please guide me through this.
how the class is instance of object?
what is the definition(body) of a default constructor in c++?
how to count 4 column with two "and" condition in oracle? e.g task_type and cust_type and service_type are 3 column and we hv to count where task_type="new"and cust_type="jdp" and resulting column name will be new cust with jdp..and also we hv to count where task_type="new"and service_type="fs" resulting column name will be new cust with fs..
I have Cleared Bank of India Clerical Examination.I just want to know how to prepare for interview and what are the parriculars that I have to submit......Pls someone help me with it
what are the various height of GSM mount and its base width ashim.port@gmail.com
computer is male or female.....???
what is difference between class and object in c++
What is meant by STL?
how can determine grounded motor when it alarm at 440volt
SQL How can make delete and insert in one query
am a textile eng. frombut with major of my course including chemical eng, subjects, can i too apply to the co.?
how can read number 1 to 100,without use anyloop.
If you were to drill a circular hole in a sheet of metal and then heat the sheet, what would happen to the size of the hole?