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

#include int fn(int v); main() { printf("%d\n",fn(7)); } int fn(int v) { if(v==1 || v==0) return 1; if(v%2==0) return fn(v/2)+2; else return fn(v-1)+3; }

1520


difference between tcp ip and open system interconnection

2079


WRITE A C PROGRAM TO REVERSE THE LINK LIST WITHOUT CREATING NEW LIST?

3266


iam from engineering information technology ... can i write group 1 exams??

1680


how to increase the water ring vacuum pump efficiency?

1666






what is a query for divide a table into two subtable?

1612


what things abutsbi

1578


plz tell me which books r important for gate exam (CSE)

1942


Is Diesel staorage tank ( 800 litres) cleaning procedure is available with any body

1593


is built-in data-type are abstract data-types in java

1468


List three things you can do with the files you create by recording your voice on your computer

3134


WHY WE SELECT U AS A PERTOLEUM ENGINEER THOUGH UR MARKS ARE LESS THEN OTHER APPLICANTS

1695


what is the quantity of cement and sand in 1 sq.m (mortar ratio ) a, 1:4 b, 1:3 c, 1:6

1562


how can one get scholership based on gre score ang how much scholarship one can get, plz suggest the way one can apply and get scholarship

2709


i cannot go to my computer to set up why?

1391