cygwin下面如使用getch()
我其实也不是想进行curses编程,就是在写数据结构的用法时查找第几个元素时,要输入的地方要用到getch(),但是我用的cygwin来编译运行的,报错说没有getch().我试着解决这个问题。
1.我曾尝试着使用在VC里面用的头文件conio.h,但是在cygwin的include包里面没有找到conio.h,所以这条路行不通。
2.我还曾试里在cywin里面添加curses.h,但是发现错误更多。
我现在只是解决如何在cygwin下面如使用getch(),这个问题????????(如果能用curses的方法解决也行。)
源程序如下>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define OK 1
#define OVERFLOW -2
#define ERROR 0
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
typedef int ElemType;
typedef int Status;
typedef struct {
ElemType *elem;
int length;
int listsize;
} Sqlist;
Status InitList_Sq(Sqlist *L) {
L->elem = (ElemType *) malloc(LIST_INIT_SIZE * sizeof (ElemType));
if (!L->elem)exit(OVERFLOW);
L->length = 0;
L->listsize = LIST_INIT_SIZE;
return OK;
}
Status ListInsert_Sq(Sqlist *L, int i, ElemType e) {
ElemType *q, *p, *newbase;
if (i < 1 || i > L->length + 1) return ERROR;
if (L->length >= L->listsize) {
newbase = (ElemType*) realloc(L->elem,
(L->listsize + LISTINCREMENT) * sizeof (ElemType));
if (!newbase)exit(OVERFLOW);
L->elem = newbase;
L->listsize += LISTINCREMENT;
}
q = &(L->elem[i - 1]);
for (p = &(L->elem[L->length - 1]); p >= q; --p)
*(p + 1) = *p;
*q = e;
++L->length;
return OK;
}
Status ListDelete_Sq(Sqlist *L, int i, ElemType *e) {
ElemType *p, *q;
if ((i < 1) || (i > L->length)) return ERROR;
p = &(L->elem[i - 1]);
*e = *p;
q = (L->elem + L->length - 1);
for (++p; p <= q; ++p)
*(p - 1) = *p;
--L->length;
return OK;
}
main() {
Sqlist Lst;
int i, n = 101;
ElemType e;
if (InitList_Sq(&Lst) == OK) {
for (i = 1; i <= n; i++)
if (ListInsert_Sq(&Lst, 1, i) != OK) break;
printf("\n");
for (i = 0; i < Lst.length; i++)
printf("i,e=%d,%d\n", i, Lst.elem[i]);
getch();
if (ListDelete_Sq(&Lst, 5, &e) == OK) {
printf("delete_elem=%d\n", e);
getch();
for (i = 0; i < Lst.length; i++)
printf("i,e=%d,%d\n", i, Lst.elem[i]);
}
}
}
请各位大侠们来帮帮忙,在此先谢了各位了