It's not legal, and consequently it's not safe. But it's easy to fix. Just use blocks in your switch statement to limit the scope of your declarations:
switch (command):
case '+': {
int key;
scanf("%i", &key);
//do stuff
break;
}
case '-': {
int key;
scanf("%i", &key);
//do stuff
break;
}