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

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

1636


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.

2088


how the class is instance of object?

1959


what is the definition(body) of a default constructor in c++?

1464


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..

1332






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

1491


what are the various height of GSM mount and its base width ashim.port@gmail.com

1402


computer is male or female.....???

1448


what is difference between class and object in c++

1692


What is meant by STL?

2288


how can determine grounded motor when it alarm at 440volt

1649


SQL How can make delete and insert in one query

1409


am a textile eng. frombut with major of my course including chemical eng, subjects, can i too apply to the co.?

1522


how can read number 1 to 100,without use anyloop.

1276


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?

676