[ Foro de C ]
/* Menu basico en C */
#include <stdio.h>
#define MAXOPCIONES 5
char opciones[MAXOPCIONES][80]=
{"Primera opcion",
"Segunda opcion",
"Tercera opcion",
"Cuarta opcion",
"Quinta opcion"};
int main() {
int i, opcion;
for (i=0; i<MAXOPCIONES; i++)
printf("%d %s\n", i+1, opciones[i]);
printf("\nEscoja una opcion: ");
scanf("%d", &opcion);
if ((opcion>=1) && (opcion<=MAXOPCIONES))
printf("Ha escogido la opcion %d: %s",
opcion, opciones[opcion-1]);
return 0;
}
/* Menu en Turbo C */
/* Ejemplo por Nacho Cabanes */
#include <conio.h>
#define MAXOPCIONES 5
char opciones[MAXOPCIONES][80]=
{"Primera opcion",
"Segunda opcion",
"Tercera opcion",
"Cuarta opcion",
"Quinta opcion"};
int main() {
int i, opcion;
clrscr();
gotoxy(10,1); cprintf("Menu");
for (i=0; i<MAXOPCIONES; i++) {
gotoxy(5, 5+ i*2);
cprintf("%d %s", i+1, opciones[i]);
}
gotoxy(5, 18);
cprintf("Escoja una opcion: ");
cscanf("%d", &opcion);
if ((opcion>=1) && (opcion<=MAXOPCIONES)) {
gotoxy(5,19);
cprintf("Ha escogido la opcion %d: %s",
opcion, opciones[opcion-1]);
}
getch(); /* Esperamos una tecla para salir */
return 0;
}
/* Menu en Turbo C (2) */
/* Ejemplo por Nacho Cabanes */
#include <conio.h>
#define MAXOPCIONES 5
#define teclaABAJO 0x50
#define teclaARRIBA 0x48
char opciones[MAXOPCIONES][80]=
{"Primera opcion",
"Segunda opcion",
"Tercera opcion",
"Cuarta opcion",
"Quinta opcion"};
int main() {
int i, opcion=1;
char tecla;
do {
clrscr();
gotoxy(10,1); cprintf("Menu");
for (i=0; i<MAXOPCIONES; i++) {
gotoxy(5, 5+ i*2);
if (i==opcion-1)
cprintf("-> %d %s", i+1, opciones[i]);
else
cprintf(" %d %s", i+1, opciones[i]);
}
gotoxy(5, 7+ MAXOPCIONES*2);
cprintf(" ENTER Aceptar");
tecla = getch();
/* Si la tecla es extendida */
if (tecla == 0) {
/* Miro si es flecha arriba o abajo */
tecla = getch();
if ((tecla == teclaARRIBA) && (opcion>1))
opcion --;
if ((tecla == teclaABAJO) && (opcion<MAXOPCIONES))
opcion ++;
}
} while (tecla != 13);
gotoxy(5,19);
cprintf("Ha escogido la opcion %d: %s",
opcion, opciones[opcion-1]);
getch(); /* Esperamos una tecla para salir */
return 0;
}
(No se puede continuar esta discusión porque tiene más de dos meses de antigüedad. Si tienes dudas parecidas, abre un nuevo hilo.)