Unix/Linux编程实践教程(一)

-------------------------------前言

呃。。。。开始入坑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);
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值