-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalgo3-3.cpp
52 lines (47 loc) · 925 Bytes
/
algo3-3.cpp
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
// algo3-3.cpp 行编辑程序,实现算法3.2
typedef char SElemType;
#include"c1.h"
#include"c3-1.h"
#include"bo3-1.cpp"
FILE *fp;
void copy(SElemType c)
{
fputc(c,fp);
}
void LineEdit()
{
SqStack s;
char ch;
InitStack(s);
printf("请输入一个文本文件,^Z结束输入:\n");
ch=getchar();
while(ch!=EOF)
{ while(ch!=EOF&&ch!='\n')
{ switch(ch)
{ case '#':if(!StackEmpty(s))
Pop(s,ch);
break;
case '@':ClearStack(s);
break;
default :Push(s,ch);
}
ch=getchar();
}
StackTraverse(s,copy);
fputc('\n',fp);
ClearStack(s);
if(ch!=EOF)
ch=getchar();
}
DestroyStack(s);
}
void main()
{
fp=fopen("ed.txt","w");
if(fp)
{ LineEdit();
fclose(fp);
}
else
printf("建立文件失败!\n");
}