• c语言行编辑程序


    static.h 头文件

    typedef struct bufferStatic{

    char *top;
    char *base;
    int staticSize;

    }bufferStatic;

    typedef int Status;


    //初始化栈
    Status InitStatck(bufferStatic *S);

    //出栈
    Status Pop(bufferStatic *S,char *c);

    //清空栈
    Status ClearStack(bufferStatic *S);

    //入栈
    Status Push(bufferStatic *S,char c);

    //销毁栈
    Status DestoryStatic(bufferStatic *S);

    //编辑缓冲区
    void LineEdit();

     staticBufferRealiz.c 文件

    #include "static.h"
    #include "stdio.h"
    #include "stdlib.h"
    #define MAX_SIZE 100
    #define INCREMENT_SIZE 10
    #define ERROR 0
    #define OK 1


    void main() {

    LineEdit();

    }
    //初始化栈
    Status InitStatck(bufferStatic *S) {

    S->base = S->top = (bufferStatic *)malloc(sizeof(char)*MAX_SIZE);
    if (!S->base)return ERROR;
    return OK;

    }
    //出栈
    Status Pop(bufferStatic *S, char *c) {

    //判断栈是否为空栈
    if (S->base == S->top)return ERROR;
    S->top--;
    *c = *(S->top);
    return OK;

    }

    //清空栈
    Status ClearStack(bufferStatic *S) {
    S->base = S->top;
    return OK;
    }

    //向栈中插入元素
    Status Push(bufferStatic *S, char c) {

    if ((S->top - S->base)>= MAX_SIZE) {

    S->base = (bufferStatic*)realloc(S->base,(MAX_SIZE+INCREMENT_SIZE)*sizeof(char));
    }

    *(S->top) = c;

    S->top++;
    return OK;

    }

    //销毁栈
    Status DestoryStatic(bufferStatic *S) {

    free(S->base);//释放掉开辟的内存
    return OK;

    }

    //编辑缓冲区
    void LineEdit() {

    bufferStatic S;

    //初始化一个空栈
    InitStatck(&S);

    char c;
    char ch = getchar();

    //全文结束符
    while (ch!=EOF)
    {

    while (ch != EOF&&ch != ' ')
    {
    switch (ch)
    {

    case '#':Pop(&S, &c);
    case '@':ClearStack(&S);
    default:Push(&S, ch);
    break;
    }
    ch = getchar();

    }
    ClearStack(&S);
    if (ch != EOF) ch = getchar();

    }

    DestoryStatic(&S);

    }

  • 相关阅读:
    poj 3318 Matrix Multiplication 夜
    hdu 4331 Image Recognition 夜
    poj 3277 City Horizon 夜
    poj 3301 Texas Trip 夜
    poj 1151 Atlantis 夜
    poj 3286 How many 0's 夜
    poj 2454 Jersey Politics 夜
    poj 1465 Multiple 夜
    poj 1095 Trees Made to Order 夜
    Null和undefined的区别?
  • 原文地址:https://www.cnblogs.com/paulversion/p/7592825.html
Copyright © 2020-2023  润新知