Escape Sequence meaning

I am not sure of what the printf escape sequence mean for this one, in addition, I added the revenue variable and it is no longer working, how would I apply another % escape sequence. I apologize if this is a dumb question, I am very new to this and searched the internet/threads before posting, any help is greatly appreciated.


1
2
printf( "%-10s%-13s%s\n", "Account", "Name", "Balance", "Revenue" );
      fscanf( cfPtr, "%d%s%lf", &account, name, &balance, &revenue );
Thank you for the quick reply, however I still am not seeing what %-10s% does or the 13s%s, I have found websites similar to that but none of them reference what the numbers are, (I found to be spacing, but unclear how to use it to create spacing) and what the %s refers to.
Reading from the reference, I immediately see several things:
% = Escape Character
- = Left-justify within the given field width; Right justification is the default (see width sub-specifier).
10 = Minimum number of characters to be printed. If the value to be printed is shorter than this number, the result is padded with blank spaces. The value is not truncated even if the result is larger.
s = String of characters

You just have to read down the page looking for what is in your escape sequence. Every printf escape sequence follows this pattern
%[flags][width][.precision][length]specifier
while all [options] are optional and the % and specifier are required.
Last edited on
% is the start of the format tag.
1
2
3
4
%-10s
- Left-justify within the given field width; Right justification is the default (see width sub-specifier).
10 Minimum number of characters to be printed. If the value to be printed is shorter than this number, the result is padded with blank spaces. The value is not truncated even if the result is larger.
s String of characters
Last edited on
Thank you, I appreciate all the help!
Topic archived. No new replies allowed.