4.程序编码
#define true 1
#define false 0
#include <stdlib.h>
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#include <conio.h>
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
typedef struct
{
char *base;
char *top;
int stacksize;
}
SqStack;
SqStack S,q;
typedef struct {
char cc[99];
int no;
}
Array;
Array a[100];
int m,n,i,j;
char name[40];
char t='\n';
FILE *fp;
/* construct an emputy shed*/
void InitStack()
{
S.base=(char *)malloc(STACK_INIT_SIZE*sizeof(char));
if(S.base==NULL)
exit(1);
S.top=S.base;
S.stacksize=STACK_INIT_SIZE;
}
void push(char e)
{
if(S.top-S.base>=S.stacksize)
{
S.base=(char*)realloc(S.base,(S.stacksize+STACKINCREMENT)*sizeof(char));
/* Attempts to shrink or expand the previously allocated block to size bytes.
Returns the address of the reallocated block which can be different than the
original address. If the block cannot be reallocated address. If the block
cannot be
S.top=S.base+S.stacksize;
S.stacksize+=STACKINCREMENT;
}
*S.top++=e;
}
char pop()
{
char e;
if(S.top==S.base)
return false;
e=*(--S.top);
return e;
}
void ClearStack()
{
S.top=S.base;
}
void DestroyStack()
{
free(S.base);
S.top=S.base;
}
int StackEmpty( )
{
if (S.top==S.base)
return true;
return false;
}
void Buffer( )
{
n=0;
m=1;
while (S.top!=S.base)
{
n=n+1;
a[m].no=a[m].no+1;
a[m].cc[n]=*(S.top-1);
S.top--;
}
}
void save()
{
printf("\n\nfile name:");
scanf("%s",&name);
fp=fopen(name,"wb");
for (i=1;i<=m;i++)
{
{ 需要完整内容的请联系QQ752018766,本文免费,转发请注明源于www.youerw.com
char ch,e;
printf("\n\n\n\t\t\t welcome to use the whole screen editor");
printf("\n\n press F6 if you want to save the file,you can save the file when you see\"^Z\" \n");
printf("\n***********************************************************\n\n");
InitStack();
ch=getchar();
while(ch!=EOF)
{
while(ch!=EOF&&ch!='\n')
{
switch(ch)
{
case '#':e=pop();break;
case '@':ClearStack();break;
default:push(ch);break;
}
ch=getchar();