Could you add a parameter in: system("color", var) in the C language?

Asked

Viewed 352 times

0

I’m creating a simple program to change the color of the system. Only, I want to give the option for the user to write the color he wants. Ex: Has the table 1: Blue 2: Green F: Red C: Yellow

F being background color and 1 font color. So looking at the table, he would choose the colors, and I would store your choice in an option variable. With that, I tried to do it that way, but it didn’t work. Does anyone have any idea how I can do it ? Obg for the attention.

/* system("color F1", opccor)*/ . system("color %c", opccor);

1 answer

2


To system() does not receive parameters, but you can use the snprintf() to compose its string command:

char buf[20];
snprintf(buf, sizeof(buf), "color %s", opccor);
system(buf);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.