Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
How can I specify a variable width in a scanf format string?
How can I specify a variable width in a scanf format string?
✍: Guest
You can't; an asterisk in a scanf format string means to suppress assignment. You may be able to use ANSI stringizing and string concatenation to construct a constant format specifier based on a preprocessor macro containing the desired width:
#define WIDTH 3
#define Str(x) #x
#define Xstr(x) Str(x) /*
scanf("%" Xstr(WIDTH) "d", &n);
If the width is a run-time variable, though, you'll have to build the format specifier at run time, too:
char fmt[10];
sprintf(fmt, "%%%dd", width);
scanf(fmt, &n);
(scanf formats like these are unlikely when reading from standard input, but might find some usefulness with fscanf or sscanf.)
2015-10-26, 1391👍, 0💬
Popular Posts:
If we have multiple AFTER Triggers on table how can we define the sequence of the triggers ? If a ta...
How To Create an Add-to-My-Yahoo Button on Your Website? - RSS FAQs - Adding Your Feeds to RSS News ...
what is a service contract, operation contract and Data Contract? - part 1 In the below sample we ha...
Can two catch blocks be executed? No, once the proper catch section is executed the control goes fin...
If we have multiple AFTER Triggers on table how can we define the sequence of the triggers ? If a ta...