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

an upper layer message is split into 10 frames each of which has an 80 percent chance of arriving undamaged.if no error control is done by the data link protocol,how many times must the message be sent on the average to get the entire thing through?

0 Answers  


What are the differences between 1 dimensional RAM and 2 dimensional RAM?

0 Answers  


what is difference between class and object in c++

0 Answers  


synchronous and asynchronous transmission

0 Answers  


Write a program in ‘C’ language that will perform the following operation on static stack. 1. push 2. pop 3. Display 4. Exit Create separate functions for each operation. The push() should accept one argument of structure type and will not return any thing. The pop() function will not receive any argument & return structure type value. The stack & top must be declare as external variable. Each element of stack will contain the following information Roll No, Std Name, Course. Use do-while loop & switch case for generating the above menu. The format of the output should is given below: S.No. Roll No. Student Name Course 1 cse01 Anil Singh B.Tech

0 Answers  


main() { int arr[]={12,14,16,18,20} printf("%u%u";arr+1,&arr+1); } //tell me the answer of this question with proper reason..:)//

1 Answers  


What is meant by STL?

0 Answers  


If Neena says "Anita's father Raman is the only son of my father-in-law Mahipal",then how is bindu ,who is the sister of Anita,related to Mahipal

1 Answers  


I am going to HAL Online test for Computer Science. Can you please mail me the model question papers ?

0 Answers   HAL,


What are the features of tata nano , technical specification of tata nano, overview of tata nano, varients of tata nano, price of tata nano, dealers of tata nano, expectation from tata nano, criticism of tata nano, tata nano hybrid ?

0 Answers   TATA,


how 2 write a program of this pattern usin for loop?? 1 2 3 4 5 6 7 8 9 10

1 Answers  


What is the weight of a foot square block of bronze.

0 Answers  


Categories
  • Civil Engineering Interview Questions Civil Engineering (5085)
  • Mechanical Engineering Interview Questions Mechanical Engineering (4452)
  • Electrical Engineering Interview Questions Electrical Engineering (16637)
  • 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)