CLI: Use printf return to compute string size instead of hardcoded values

This commit is contained in:
Grégory Soutadé 2017-07-19 19:11:52 +02:00
parent 86e926e268
commit 39582e0f26

View File

@ -81,19 +81,19 @@ static void signal_handler(int signum)
static void display_password(char* password, int time) static void display_password(char* password, int time)
{ {
int length; int print_len = 0;
for (; time && !s_stop_display; time--) for (; time && !s_stop_display; time--)
{ {
printf("\r(%02d) Password found: %s", time, password); print_len = printf("\r(%02d) Password found: %s", time, password);
fflush(stdout); fflush(stdout);
sleep(1); sleep(1);
} }
// Clear line // Clear line
print_len++; // For C or Z
printf("\r"); printf("\r");
length = 4 + 17 + strlen(password) + 1 + 1 /* For Ctrl+Z/C */; while (print_len--)
while (length--)
printf(" "); printf(" ");
printf("\n"); printf("\n");
} }