Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

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

1769


What is frog testing? What is cone model?

1830


How can we share data between actions in qtp..pls tell me

2156


What would be your first invention?

1103


write a progremme using function 0f prime no.?

1736


how to generate linked implementation of sparse matrix?

1938


what are purchase order , sales order idoc names and idoc types

2022


#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; }

1966


Write a test case plan for a typical banking application which involves functionalities like Balance enquiry, deposit, fund transfer etc. Make your assumptions and mention the same in your answer sheet.

1977


what are the no. of leaf nodes in a fibonacci tree ?

2422


why view is created in database

1647


Q1. A. Compare the advantages and disadvantages of a three- dimensional monitor using a varifocal mirror with a stereoscopic system. B. Write a routine to implement the polymarker function.

2151


what do you mean by CPU register?

2013


write a pgm to accept an array of names & name & check whether the name is present in the array. return the count of occurance. use following array as input; {"Dave","Ann","dev","merry"}

1723


what is different between static block and public static void main??

1799