Skip to content

Commit

Permalink
Add space flag
Browse files Browse the repository at this point in the history
  • Loading branch information
MaJerle committed Aug 29, 2020
1 parent 9a56913 commit dc05c8b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
19 changes: 4 additions & 15 deletions dev/VisualStudio/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ main(void) {
printf_run(NULL, "%0*d", 10, -123);
printf_run(NULL, "%zu", (size_t)10);
printf_run(NULL, "%ju", (uintmax_t)10);
printf_run(NULL, "% d", 1024);
printf_run(NULL, "% 4d", 1024);
printf_run(NULL, "% 3d", 1024);
printf_run(NULL, "% 3f", 32.324);

/* string */
printf_run(NULL, "%*.*s", 8, 12, "This is my string");
Expand Down Expand Up @@ -138,21 +142,6 @@ main(void) {
printf_run(NULL, "%llb abc", 123);
printf_run(NULL, "%llb abc", 123);
printf_run(NULL, "%b", 4);
//printf_run(NULL, "%10b", 8);
//printf_run(NULL, "%010b", 8);

/* Floats */
printf_run(NULL, "%f", 12.13);
printf_run(NULL, "%.3f", 12.1337);
printf_run(NULL, "%.25f", 12.1337);

/* Engineering */
printf_run(NULL, "%e", 2.5f);
printf_run(NULL, "%e", 43433.23f);

/* A */
printf_run(NULL, "%a", 2.5f);
printf_run(NULL, "%a", 43433.23f);

/* Array test */
uint8_t my_arr[] = { 0x00, 0x01, 0x02, 0x03, 0x04 };
Expand Down
6 changes: 5 additions & 1 deletion lwprintf/src/lwprintf/lwprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,14 @@ prv_out_str_before(lwprintf_int_t* p, size_t buff_size) {
}
}

/* Add negative sign (or positive in case of + flag) before when zeros are used to fill width */
/* Add negative sign (or positive in case of + flag or space in case of space flag) before when zeros are used to fill width */
if (p->m.flags.zero) {
if (p->m.flags.is_negative) {
p->out_fn(p, '-');
} else if (p->m.flags.plus) {
p->out_fn(p, '+');
} else if (p->m.flags.space) {
p->out_fn(p, ' ');
}
}

Expand Down Expand Up @@ -285,6 +287,8 @@ prv_out_str_before(lwprintf_int_t* p, size_t buff_size) {
p->out_fn(p, '-');
} else if (p->m.flags.plus) {
p->out_fn(p, '+');
} else if (p->m.flags.space) {
p->out_fn(p, ' ');
}
}

Expand Down

0 comments on commit dc05c8b

Please sign in to comment.