免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 7042 | 回复: 12
打印 上一主题 下一主题

fopen("/dev/tty","r")失败,errno=25 ,什 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-07-21 11:34 |只看该作者 |倒序浏览
如题,运行环境:VMware+debian3.1+X Window
谁能告诉我什么原因吗?

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
2 [报告]
发表于 2005-07-21 11:36 |只看该作者

fopen("/dev/tty","r")失败,errno=25 ,什

perror("fopen";
printf("%s\n",strerror(errno));

论坛徽章:
0
3 [报告]
发表于 2005-07-21 11:46 |只看该作者

fopen("/dev/tty","r")失败,errno=25 ,什

说是 Inappropriate ioctl for device 什么意思?

论坛徽章:
0
4 [报告]
发表于 2005-07-21 11:48 |只看该作者

fopen("/dev/tty","r")失败,errno=25 ,什

我运行的是《linux程序设计》第5章里的例程啊,到底什么原因呢,俺是菜鸟

论坛徽章:
0
5 [报告]
发表于 2005-07-21 11:49 |只看该作者

fopen("/dev/tty","r")失败,errno=25 ,什

试下这样行不行
fopen("\\dev\\tty","r"

论坛徽章:
0
6 [报告]
发表于 2005-07-21 11:53 |只看该作者

fopen("/dev/tty","r")失败,errno=25 ,什

楼上那样就会产生段错误

论坛徽章:
0
7 [报告]
发表于 2005-07-21 11:55 |只看该作者

fopen("/dev/tty","r")失败,errno=25 ,什

#include <errno.h>;

#include <stdio.h>;
#include <unistd.h>;
char *menu[]={
        "a - add new record",
        "d - delete record",
        "q - quit",
        NULL,
};
int getchoice(char *greet, char * choices[],FILE *in,FILE *out);
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,%d\n",errno);
                perror("fopen";
                fprintf(stderr,"%s\n",strerror(errno));
                exit(1);
        }
       
        do{
                choice = getchoice("lease select an  action ",menu,input,output);
                printf("You have chosen: %c\n",choice);
        }while(choice != 'q');
        exit(0);
}

int getchoice(char * greet, char * choices[],FILE *in,FILE *out)
{
        int chosen = 0;
        int selected;
        char ** option;
        do{
                fprintf(out,"Choice: %s\n",greet);
                option = choices;
                while( *option){
                        fprintf(out,"%s\n",*option);
                        option++;
                }
                do{
                selected = fgetc(in);
                }while(selected=='\n');
                option = choices;
                while(*option){
                        if(selected == *option[0]){
                                chosen = 1;
                                break;
                        }
                        option ++;
                }
                if(!chosen){
                        fprintf(out,"Incorrect choice,select again \n";
                }
        }while(!chosen);
        return selected;
}

论坛徽章:
0
8 [报告]
发表于 2005-07-21 11:56 |只看该作者

fopen("/dev/tty","r")失败,errno=25 ,什

大家帮忙编译一下,看看是否能行好吗?

论坛徽章:
0
9 [报告]
发表于 2005-07-21 11:56 |只看该作者

fopen("/dev/tty","r")失败,errno=25 ,什

tty 是文件还是目录???

论坛徽章:
0
10 [报告]
发表于 2005-07-21 12:01 |只看该作者

fopen("/dev/tty","r")失败,errno=25 ,什

/dev/tty是当前的终端或会话,书上这么说的,算是文件了
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP