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



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

Answer / 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

More Engineering AllOther Interview Questions

how to create user name stape by stape in cisco router {with command}

0 Answers  


What is the basic difference between injection speed and injection pressure in an injection molding machine?

0 Answers  


What is The Need of Template?

0 Answers  


How we calculate the recovery of steam as per coal in a boiler if we know the calorific value of coal?

0 Answers  


Explain Belady's Anomaly.

0 Answers  






Create an midp application which examines that a phone number which has enters is in the given format * Area code should be one of the following:040,041,050,0400,044

0 Answers  


PLZ SOMEONE TELL ME WHICH TYPE OF QUESTIONS IS ASKED IN HLL(Hindustan latex ltd.)mangmt trainee entrance exam?

0 Answers  


4) Write a program that takes a 5 digit number and calculates 2 power that number and prints it. I did the following program and is this correct

1 Answers  


Design a counter for the following binary sequence: 0,4,5,3,1,6,2,7 and repeat. Use JK flip-flops.

3 Answers   IIIT, Infotech, University, UNW,


HELLO EVERYONE ON YAHOO , I'M IN NIGERIA AND I Will LIKE TO MOVE AND WORK IN CANADA , ANY SKILLED WORK IS OK BY ME AND THE PERSON WILL PAY THE BILL FOR IT, I WILL SERVE THE PERSON FOR THE EXPENSES.......... LOVE TO READ FROM YOU SOONEST AS YOU WISH TO HELP ME OUT

0 Answers  


Draw the diagram showing the function stack, illustrating the variables that were pushed on the stack at the point when function f2 has been introduced . type def struct { double x,double y} point; } main( int argc, char *arg[3]) { double a; int b,c; f1(a,b); } f1(double x, int y) {point p; stack int n; f2(p,x,y) } f2(point p, double angle) { int i,j,k,int max;

0 Answers   Geometric Software,


Bhanu spends 30% of his income on petrol on scooter. ? of the remaining on house rent and the balance on food. If he spends Rs.300 on petrol then what is the expenditure on house rent?

1 Answers   TCS,


Categories
  • Civil Engineering Interview Questions Civil Engineering (5085)
  • Mechanical Engineering Interview Questions Mechanical Engineering (4451)
  • Electrical Engineering Interview Questions Electrical Engineering (16632)
  • Electronics Communications Interview Questions Electronics Communications (3918)
  • Chemical Engineering Interview Questions Chemical Engineering (1095)
  • Aeronautical Engineering Interview Questions Aeronautical Engineering (239)
  • Bio Engineering Interview Questions Bio Engineering (96)
  • Metallurgy Interview Questions Metallurgy (361)
  • Industrial Engineering Interview Questions Industrial Engineering (259)
  • Instrumentation Interview Questions Instrumentation (3014)
  • Automobile Engineering Interview Questions Automobile Engineering (332)
  • Mechatronics Engineering Interview Questions Mechatronics Engineering (97)
  • Marine Engineering Interview Questions Marine Engineering (124)
  • Power Plant Engineering Interview Questions Power Plant Engineering (172)
  • Textile Engineering Interview Questions Textile Engineering (575)
  • Production Engineering Interview Questions Production Engineering (25)
  • Satellite Systems Engineering Interview Questions Satellite Systems Engineering (106)
  • Engineering AllOther Interview Questions Engineering AllOther (1379)