-------------------------------前言
呃。。。。开始入坑linux。参考书当然是《Unix/Linux编程实践教程》
现写下心得笔记,有什么不对的,请大家指正哈。
------------------------------修正
2018.5.13
貌似我用自己的虚拟机也不行,先暂时放下吧,这个还分析不了原因。。。。难道是因为虚拟机?要自己装一个系统才能使用tty?暂时不懂。。。。。
试了这位博主的程序,/dev/tty可以用,不知道自己的问题出在哪,不过有方向了,先mark
https://blog.csdn.net/a7055117a/article/details/50558089
-------------------------------正文
直接上代码:这是书上的例程,我直接敲了一遍
/*more01.c - version 0.1 of more
*read and print 24 lines then pause for a few special commands
**************************Modify*************************
*************************Version0.2**********************
*add the file (/dev/tty) which is able to imput and output like keyboard and screen directly
*result:i don't need to press the 'Entry' to use my function
*/
#include <stdlib.h>
#include <stdio.h>
#define PAGELEN 24
#define LINELEN 512
void do_more(FILE *);
int see_more(FILE* ); //add a parameter,FILE*
int main(int ac,char *av[])
{
FILE * fp;
if(1 == ac)
do_more(stdin);
else
while(--ac)
{
if((fp = fopen(*++av,"r")) != NULL)
{
do_more(fp);
fclose(fp);
}
else
exit(1);
}
return 0;
}
/*
* read PAGELEN lines,then call see_more() for further instructions
*/
void do_more(FILE * fp)
{
char line[LINELEN];
int num_of_lines = 0;
int see_more(),reply;
FILE * tty_fp; //add the file for tty
tty_fp = fopen("/dev/tty","r");
if(tty_fp == NULL)
{
printf("eeeee");
exit(1);