当前位置: 技术问答>linux和unix
关于curses函数的一个程序
来源: 互联网 发布时间:2015-08-14
本文导语: 我的一个程序,在redhat Linux 9.0上运行时不成功,程序为一显示界面的范例,代码如下,恳请高手帮忙: #include #include #include #include #include static FILE *output_stream = (FILE *)0; char *menu[...
我的一个程序,在redhat Linux 9.0上运行时不成功,程序为一显示界面的范例,代码如下,恳请高手帮忙:
#include
#include
#include
#include
#include
static FILE *output_stream = (FILE *)0;
char *menu[]={"a - add new record","d - delete record","q - quit",NULL};
int getchoice(char *greet,char *choices[],FILE *in,FILE *out);
int char_to_terminal(int char_to_write);
int main()
{
int choice=0;
FILE *input;
FILE *output;
if(!isatty(fileno(stdout)))
{
fprintf(stderr,"You are not a terminal,OK.n");
}
input=fopen("/dev/tty","r");
output=fopen("/dev/tty","w");
if(!input ¦ ¦ !output)
{
fprintf(stderr,"Unable to open /dev/tty n");
exit(0);
}
printf("Hello Linux!");
do
{
choice=getchoice("Please select an action",menu,input,output);
printf("You have chosen: %cn",choice);
}while(choice != 'q');
exit(0);
}
int getchoice(char *greet,char *choices[],FILE *in,FILE *out)
{
int chosen=0;
int selected;
int screenrow,screencol=10;
char **option;
char *cursor,*clear;
output_stream=out;
setupterm(NULL,fileno(out),(int *)0);
cursor=tigetstr("cup");
clear=tigetstr("clear");
screenrow=4;
printf("Hello Linuxn");
tputs(clear, 1,char_to_terminal);
tputs(tparm(cursor,screenrow,screencol),1,char_to_terminal);
fprintf(out,"Choice: %s",greet);
screenrow+=2;
option=choices;
while(*option)
{
tputs(tparm(cursor,screenrow,screencol),1,char_to_terminal);
fprintf(out,"%s",*option);
screenrow++;
option++;
}
do
{
selected=fgetc(in);
option=choices;
while(*option)
{
if(selected==*option[0])
{
chosen=1;
break;
}
}
if(!chosen)
{
tputs(tparm(cursor,screenrow,screencol),1,char_to_terminal);
fprintf(out,"Incorrect choice,select againn");
}
}while(!chosen);
tputs(clear,1,char_to_terminal);
return selected;
}
int char_to_terminal(int char_to_write)
{
if(output_stream)
putc(char_to_write,output_stream);
return 0;
}
#include
#include
#include
#include
#include
static FILE *output_stream = (FILE *)0;
char *menu[]={"a - add new record","d - delete record","q - quit",NULL};
int getchoice(char *greet,char *choices[],FILE *in,FILE *out);
int char_to_terminal(int char_to_write);
int main()
{
int choice=0;
FILE *input;
FILE *output;
if(!isatty(fileno(stdout)))
{
fprintf(stderr,"You are not a terminal,OK.n");
}
input=fopen("/dev/tty","r");
output=fopen("/dev/tty","w");
if(!input ¦ ¦ !output)
{
fprintf(stderr,"Unable to open /dev/tty n");
exit(0);
}
printf("Hello Linux!");
do
{
choice=getchoice("Please select an action",menu,input,output);
printf("You have chosen: %cn",choice);
}while(choice != 'q');
exit(0);
}
int getchoice(char *greet,char *choices[],FILE *in,FILE *out)
{
int chosen=0;
int selected;
int screenrow,screencol=10;
char **option;
char *cursor,*clear;
output_stream=out;
setupterm(NULL,fileno(out),(int *)0);
cursor=tigetstr("cup");
clear=tigetstr("clear");
screenrow=4;
printf("Hello Linuxn");
tputs(clear, 1,char_to_terminal);
tputs(tparm(cursor,screenrow,screencol),1,char_to_terminal);
fprintf(out,"Choice: %s",greet);
screenrow+=2;
option=choices;
while(*option)
{
tputs(tparm(cursor,screenrow,screencol),1,char_to_terminal);
fprintf(out,"%s",*option);
screenrow++;
option++;
}
do
{
selected=fgetc(in);
option=choices;
while(*option)
{
if(selected==*option[0])
{
chosen=1;
break;
}
}
if(!chosen)
{
tputs(tparm(cursor,screenrow,screencol),1,char_to_terminal);
fprintf(out,"Incorrect choice,select againn");
}
}while(!chosen);
tputs(clear,1,char_to_terminal);
return selected;
}
int char_to_terminal(int char_to_write)
{
if(output_stream)
putc(char_to_write,output_stream);
return 0;
}
|
回ccwwcsdnc:
if(!input ¦ ¦ !output)
{
fprintf(stderr,"Unable to open /dev/tty n");
exit(0);
}
========================================================================
错了,应该是:
if(!input||!output)
{
fprintf(stderr,"Unable to open /dev/tty n");
exit(1);
}
if(!input ¦ ¦ !output)
{
fprintf(stderr,"Unable to open /dev/tty n");
exit(0);
}
========================================================================
错了,应该是:
if(!input||!output)
{
fprintf(stderr,"Unable to open /dev/tty n");
exit(1);
}
|
while(*option)
{
if(selected==*option[0])
{
chosen=1;
break;
}
///----------
option++;
}
{
if(selected==*option[0])
{
chosen=1;
break;
}
///----------
option++;
}
|
if(!input ¦ ¦ !output)
=========
brvbar是什么?
=========
brvbar是什么?