From 8c82fc3f6ddd3915d07f5563c7d5b0d3783ab88d Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Tue, 24 Feb 2015 14:02:31 +0100 Subject: Simplify code in status_ask_choice() Signed-off-by: Lukas Fleischer --- src/utils.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/utils.c b/src/utils.c index 613e4bc..f726260 100644 --- a/src/utils.c +++ b/src/utils.c @@ -197,19 +197,17 @@ void status_mesg(const char *msg1, const char *msg2) int status_ask_choice(const char *message, const char choice[], int nb_choice) { - int i, ch; - char *tmp; /* "[4/2/f/t/w/.../Z] " */ char avail_choice[2 * nb_choice + 3]; + int i, ch; avail_choice[0] = '['; - avail_choice[1] = '\0'; - for (i = 1; i <= nb_choice; i++) { - asprintf(&tmp, (i == nb_choice) ? "%c] " : "%c/", choice[i]); - strcat(avail_choice, tmp); - mem_free(tmp); + avail_choice[i * 2 - 1] = choice[i]; + avail_choice[i * 2] = '/'; } + avail_choice[nb_choice * 2] = ']'; + avail_choice[nb_choice * 2 + 1] = '\0'; status_mesg(message, avail_choice); -- cgit v1.2.3-70-g09d2