行编辑程序
接受用戶從終端輸入的數據,當用戶發現剛剛鍵入的字符是錯誤的,‘#’表示前一個字符無效;‘@’表示當前行或之前的數據無效。
#include<iostream>
#include<stdio.h>
using namespace std;
const int MAX_LENGTH=100;
struct Stack{
char *top;
char *base;
int stacksize;
};
void InitStack(Stack &S){
S.base=new char[MAX_LENGTH];
S.top=S.base;
S.stacksize=MAX_LENGTH;
}
void Push(Stack &S,char e){
*(S.top++)=e;
}
void Pop(Stack &S,char &e){
if(S.top==S.base){
return;
}
e=*(--S.top);
}
void ClearStack(Stack &S){
S.top=S.base;
}
void PrintStack(Stack &S){
char *e=S.base;
while(e != S.top){
cout<<*e;
e++;
}
cout<<'
';
}
void LineEdit(){
Stack S,t;
InitStack(S);
char e=getchar();
while(e!=EOF){
while(e!=EOF && e!='
'){
switch(e){
case '#':Pop(S,e); break;
case '@': ClearStack(S);break;
default:Push(S,e);
}
e=getchar();
}
PrintStack(S);
ClearStack(S);
if(e != EOF){
e=getchar();
}
};
}
int main(){
LineEdit();
return 0;
}
總結
- 上一篇: ovftool使用部署——导出ova/o
- 下一篇: VC++中内存对齐