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

When a local variable has the same name as a field the local variable's name does this to the field's name?

When a local variable has the same name as a field, it shadows the field's name within its scope. This means that within that scope, any reference to the variable name will refer to the local variable rather than the field. As a result, the field becomes inaccessible directly by that name until the scope of the local variable ends. This can lead to confusion and potential bugs if not managed properly.


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 skip a space in printf?

In printf, you can skip a space by using the formatting options to control the output. For example, you can use the * width specifier to specify a minimum field width, or you can include a - flag to left-align your output. Additionally, simply omitting spaces in the format string will prevent extra spaces from being printed. If you want to skip a specific number of spaces, you can use printf("%*s", n, ""); where n is the number of spaces to skip.


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!

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 data type should Phil use for the Social Security Number field?

Phil should use a string data type for the Social Security Number (SSN) field. This is because SSNs can contain leading zeros, and using a numeric data type could lead to loss of this information. Additionally, SSNs are not used for calculations, so a string format is more appropriate to preserve the exact format, including any dashes.


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.


When a local variable has the same name as a field the local variable's name does this to the field's name?

When a local variable has the same name as a field, it shadows the field's name within its scope. This means that within that scope, any reference to the variable name will refer to the local variable rather than the field. As a result, the field becomes inaccessible directly by that name until the scope of the local variable ends. This can lead to confusion and potential bugs if not managed properly.


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 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 instance variable in java?

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


What is the unique name called for a data field?

String