What would you like to do?

Can you specify variable field width in a scanf format string If possible how?

already exists.

Would you like to merge this question into it?

already exists as an alternate of this question.

Would you like to make it the primary and merge this question into it?

exists and is an alternate of .

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. 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.
Thanks for the feedback!

What is the purpose of the format specifier?

There are many types of format specifier. Exp:%d (To show the integer) %c(To show the character) %f(Float are digits with decimal points to use it to show them) %s(String to

What is string variable?

A string variable is a programming language construct that holds text. For example, the text "The sky is blue" could be stored to a string variable, then later in the program,

How is string variable different from char variable?

A char is a single character. A String is a collection of  characters. It may be empty (zero characters), have one character,  two character, or many characters - even a fai