answersLogoWhite

0

Answer

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.

Answer

If you want to specify a variable width in a printf format string (as opposed to scanf), you can do the following:

printf("%*d", width, num);

That will use the value of "width" as the width for formatting the value of "num" as a decimal integer.

User Avatar

Wiki User

15y ago

What else can I help you with?

Continue Learning about Engineering

How can you call a function given its name as a string?

we have to construct a table of two field structures,where the first field is the funtion name as a string and the second field is just the function name.then search the table to get a string match in the first field and use the second field to call the function.


What does Error converting data type to numeric means?

You must have declared a method which tries to convert a variable/field value into a numeric value but that is not possible. Refer to the line on which the error is found and remove the method which tries to convert the variable/field. Note: Java allows type casting so a string cannot be converted into integer even if a method tries to change the value


How do you sort string values by field calculator in ArcMap?

For example, there are few string values of "1-5", ">5", "0-0.9", and "<0" from one field in attribute table. Then I need to sort both "1-5" and ">5" to a new field. How do I make the field calculator for this? Thank you!


What is a field in java?

A field is an attribute. A field may be a class's variable, an object's variable, an object's method's variable, or a parameter of a function. class bike{ static int bikes;int gear;int cadence; void create( int newGear, int newCadence ){bikes = bikes + 1;gear = newGear; cadence = newCadence;} int getSpeed(){int speed = gear*cadence*5*3.141;return speed;}} 'bikes' is a class's variable (class variable) (static field). 'gear' and 'cadence' could be an object's variables (instance variables) (non-static fields). 'speed' is an object's method's variable (local variable). 'newGear' and 'newCadence' are parameters of a function (parameters). Refer to related links section


Relationship between flux density and field strength?

In simple terms, if flux density increases, then field strength increases and vice versa. The flux density is equivalent to field strength times with a variable.

Related Questions

In IPv6 each address contains an or a variable-length field at the beginning of the address that indicates what type of address it is?

format prefix


What is variable field length?

The amount of data stored in such fields can vary in length. Usually you do specify a maxmimum length so that databases can optimize how data is stored and accessed.


What is a database field format?

A database field format refers to the data type and structure used to define a specific field within a database table. It determines how data is stored, validated, and interpreted within that field, such as text, numbers, dates, or binary data. Common field formats include VARCHAR for variable-length text, INT for integers, and DATE for dates.


How can you call a function given its name as a string?

we have to construct a table of two field structures,where the first field is the funtion name as a string and the second field is just the function name.then search the table to get a string match in the first field and use the second field to call the function.


What characteristics in a database fields may have such as data type field name field size and field format?

What characteristics could a database field have, such as data type, field name, field size and field format?


How do you validate empty fields in PHP?

PHP provides a function called empty($var), which tests if $var is "empty." Empty has an odd definition, since the function returns true if the variable loosely equates to False. Although a zero-length string would be considered empty, so would the string "0" (among other irrelevant values).To accept the value "0" from a field, use strlen($var). It tests the length of any variable, after casting it to a string. If this function truly equals integer zero (compared with triple-equals), the variable must be empty.


In craps which of these numbers is NOT in the field?

You didn't specify which numbers. The field numbers are 2,3,4,9,10,11,12. The numbers that are not in the field are 5,6,7,8


What is instance variable in java?

That refers to a variable attached to an object - also known as a field.


What does Error converting data type to numeric means?

You must have declared a method which tries to convert a variable/field value into a numeric value but that is not possible. Refer to the line on which the error is found and remove the method which tries to convert the variable/field. Note: Java allows type casting so a string cannot be converted into integer even if a method tries to change the value


What is the unique name called for a data field?

String


What is the standard citation format for academic papers in the field of law?

The standard citation format for academic papers in the field of law is typically the Bluebook citation style.


Which field of study does string theory seek to unite quantum physics with?

String theory seeks to unite quantum physics with the theory of general relativity in the field of theoretical physics.