I'm using arrow keys as inputs to move a printf
arrow ("==>") up and down a printf
menu.
I'm using a function that counts where the arrow should be and using switch
cases and printf("\n==>")
to place where the arrow should be, but it prints the menu in a new line as well.
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <windows.h>
void menu(void);
int arrowPos(void);
int main(void)
{
int aDet, aDet2;
int aCnt;
for(;;)
{
aDet = getch();
aDet2 = 0;
if(aDet == 0xE0)
{
aDet2 = getch();
if(aDet2 == 80) arrowPos();
}
}
return 0;
}
int arrowPos(void)
{
int aCnt;
LOOP:
aCnt++;
switch(aCnt)
{
case 1:
system("cls");
printf("==>");
// menu();
break;
case 2:
system("cls");
printf("\n==>");
break;
case 3:
system("cls");
printf("\n\n==>");
// menu();
break;
case 4:
aCnt = 0;
goto LOOP;
break;
}
menu();
//printf("%d",aCnt);
}
void menu(void)
{
printf("Option 1\n");
printf("Option 2\n");
printf("Option 3");
}
When it prints the menu on the second and third arrow the menu is also printed on a new line.
Instead of looking like
Option1
Option2
==>Option3
it looks like
==>Option1
Option2
Option3