标签:memset turn static nbsp 大数据 pre amp oid struct
数组是一个大的集合,定义一个大数据类型变量 (看成整体)
#include "stdafx.h" #include <stdio.h> #include <string.h> #include <math.h> // 顺序stack #define Max 20 struct stack { char buf[Max]; int pos;// stack位置 }; static struct stack stack_test; static int init_stack(void * pStack) { if (pStack == NULL) { return -1; } struct stack* ptmpstack = (struct stack*)pStack; ptmpstack->pos = 0; memset(ptmpstack, 0, sizeof(struct stack)); return 0; } static int push_stack(struct stack* pStack, int data) { if (pStack == NULL) { return -1; } if (pStack->pos == Max - 1) { printf("stack 堆的太高了 超过了\n"); return -1; } pStack->buf[pStack->pos] = data; pStack->pos++; return 0; } static int pop_stack(struct stack* pStack) { if (pStack == NULL) { return -1; } if (pStack->pos == 0) { printf("到stack 底部 底部 底部了 \n"); return -1; } pStack->buf[pStack->pos] = 0; pStack->pos--; return 0; } int main() { init_stack(&stack_test); push_stack(&stack_test, 10); push_stack(&stack_test, 10); push_stack(&stack_test, 10); push_stack(&stack_test, 10); push_stack(&stack_test, 10); push_stack(&stack_test, 10); push_stack(&stack_test, 10); push_stack(&stack_test, 10); push_stack(&stack_test, 10); push_stack(&stack_test, 10); push_stack(&stack_test, 10); push_stack(&stack_test, 10); push_stack(&stack_test, 10); push_stack(&stack_test, 10); push_stack(&stack_test, 10); push_stack(&stack_test, 10); push_stack(&stack_test, 10); push_stack(&stack_test, 10); push_stack(&stack_test, 10); push_stack(&stack_test, 10); push_stack(&stack_test, 10); push_stack(&stack_test, 10); push_stack(&stack_test, 10); push_stack(&stack_test, 10); push_stack(&stack_test, 10); push_stack(&stack_test, 10); pop_stack(&stack_test); pop_stack(&stack_test); pop_stack(&stack_test); pop_stack(&stack_test); pop_stack(&stack_test); pop_stack(&stack_test); pop_stack(&stack_test); pop_stack(&stack_test); pop_stack(&stack_test); pop_stack(&stack_test); pop_stack(&stack_test); pop_stack(&stack_test); pop_stack(&stack_test); pop_stack(&stack_test); pop_stack(&stack_test); pop_stack(&stack_test); pop_stack(&stack_test); pop_stack(&stack_test); pop_stack(&stack_test); pop_stack(&stack_test); pop_stack(&stack_test); pop_stack(&stack_test); pop_stack(&stack_test); pop_stack(&stack_test); pop_stack(&stack_test); pop_stack(&stack_test); pop_stack(&stack_test); pop_stack(&stack_test); pop_stack(&stack_test); pop_stack(&stack_test); pop_stack(&stack_test); pop_stack(&stack_test); while (1); return 0; }
标签:memset turn static nbsp 大数据 pre amp oid struct
原文地址:https://www.cnblogs.com/nowroot/p/12735241.html