English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Ok so the notes online has an example where it says

/*display results in tabular format*/
printf(" 1%13d\n" , "Face", "Frequency");
printf(" 1%13d\n" , "Frequency");
printf(" .....

I know that it should be in a table and that face and frequency are like the categories for the table but what does the thing in the quotes mean???

I know \n is space %s and is the character string but what about the rest???

2007-03-20 16:14:34 · 6 answers · asked by Anonymous in Computers & Internet Programming & Design

6 answers

it will print some garbage
as face is a string not an integer

2007-03-21 00:50:43 · answer #1 · answered by Anonymous · 0 1

1) \n is actually a line feed, not a space.
2) printf() takes a format string and a variable number of arguments whose values get swapped into the format string when printf() is executed. In other words, sequences in the format string like "%s" and "%d" are swapped with the values of variables. %d means that the variable that's going to get swapped in is a numeric type. %13d specifies some formatting about how the number should look when printed (in this case it should always be 13 characters long with padding added if necessary). Format strings can vary somewhat depending on the libc implementation, so your best bet to getting a full description of how they work is to hit up the documentation that came with your compiler.

2007-03-20 23:32:09 · answer #2 · answered by Super J Dynamite 2 · 0 0

" 1 %13d \n"

The first three characters ( space, one, space) would print as they are. Then the %13d says to print an integer with a width of 13 spaces.

The first printf is invalid in that two variables are passed but only one is expected.

2007-03-20 23:23:57 · answer #3 · answered by BigRez 6 · 0 0

Are you sure you reproduced the code correctly? Even if this compiles it is a string printed as number and I am sure some strange garbage output will happen.

\n is newline; not space, there is a world difference between the two in programming. %d is number, integer if I remember right although I used %i, usually a format code can occur between % and d (or s i f whatever other codified character) in this case 13 within %d dictates to have the number output formatted within 13 digits, or padded with spaces to form 13 cells for output.

2007-03-20 23:31:58 · answer #4 · answered by Andy T 7 · 0 0

the first printf() has too many arguments. The second should print a '1' followed by the integer representation of the pointer to the string "Frequency".

2007-03-20 23:29:56 · answer #5 · answered by the redcuber 6 · 0 0

1%13d,
the number before d means that the width of that given number, and also you miss the control string for the remaining two strings that you have passed. So It wont display. another mistake you give only d and give string for that d, so it will display starting address of that string.

2007-03-20 23:41:55 · answer #6 · answered by sridhar b 2 · 0 0

fedest.com, questions and answers