-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path8_25.c
36 lines (36 loc) · 786 Bytes
/
8_25.c
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
//vi-like editor:
//8/25/2012
#include<stdio.h>
#include<string.h>
void main(int argc,char *argv[])
{
FILE *fp;
char ch;
char s[4];
fp=fopen(argv[1],"r+");
while(1)
{
ch=fgetc(fp);
if(ch==EOF) break;
printf("%c",ch);
}
while(1)
{
ch=getche();
/*if(strcmp(s,":w")==0){fclose(fp);fp=fopen(argv[1],"a");continue;}
else if(strcmp(s,":q")==0)break;
else if(strcmp(s,))
fputs(s,fp);
fputs("\n",fp);*/
if(ch==27)
{
puts("\n\n");
gets(s);
if(strcmp(s,":w")==0){fclose(fp);}
else if(strcmp(s,":q")==0){break;}
}
else if(ch=='\r'){ puts("\r");fputs("\n",fp);}
else fputc(ch,fp);
}
fclose(fp);
}