-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmore1.c
More file actions
72 lines (67 loc) · 1.18 KB
/
more1.c
File metadata and controls
72 lines (67 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*************************************************************************
> File Name: more1.c
> Author: ma6174
> Mail: ma6174@163.com
> Created Time: Wed 26 Feb 2014 11:14:18 PM CST
************************************************************************/
#include<stdio.h>
#define PAGE_LEN 24
#define LINE_LEN 1024
char get_a_char();
int display_text(FILE * fp ,int num);
int main(int argc,char **argv)
{
int status = 1;
FILE *fp;
char ch;
char ch1;
if(argc<=1)
{
fp = stdin;
}
else
fp = fopen(argv[1],"r");
if(fp!=NULL)
{
display_text(fp,PAGE_LEN);
while(status)
{
printf("\033[m----more----\033[m");
ch = getchar();
printf("The char is %d\n", ch);
fflush(stdin);
switch(ch)
{
case ' ':
status = display_text(fp, PAGE_LEN);
break;
case 'n':
status = display_text(fp, 1);
break;
case 'q':
return 1;
default:
break;
}
}
}
return 0;
}
char get_a_char()
{
return getchar();
}
int display_text(FILE *fp,int num)
{
fflush(stdin);
int status = 1;
char buff[LINE_LEN];
while((fgets(buff,LINE_LEN,fp)!=NULL) && (num>0))
{
fputs(buff,stdout);
num--;
}
if(num>0)
status = 0;
return status;
}