void LineEdit(){
Stack S;
InitStack(S);
char ch;
printf("请输入...\n");
fflush(stdout);
ch = getchar();//获取输入字符
while (ch != EOF){
while (ch != EOF && ch != '\n'){
ELEMTYPE e;
switch (ch){
case '#':
if (StackEmpty(S)){//栈空时不能退格
printf("未输入任何字符.\n");
return;
}
Pop(S, e);//退格(即出栈)
break;
case '@':
if (StackEmpty(S)){//栈空时不能退行
printf("未输入任何字符.\n");
return;
}
ClearStack(S);//退行(即清空栈)
break;
default:
if (StackFull(S)){
printf("最多输入%d个字符\n", MAXSIZE);
return;
}
Push(S, ch);//默认是进栈
break;
}
ch = getchar();//进行下一次输入
}
printStack(S);//先打印栈
fflush(stdout);
ClearStack(S);//再清空栈
if (ch != EOF)//当输入为换行符
ch = getchar();//开始下一行输入
}
ClearStack(S);//输入为EOF(Ctrl+Z),清空栈,退出程序
}
栈应用之行编辑程序(C语言)
最新推荐文章于 2024-03-03 18:52:30 发布