我将值传递给CreateTask中的类的属性,使用AsyncTask类之外的属性值,属性值不会更改,但属性值会在按钮单击事件中更改。
AsyncTask类中的CreateTask,AsyncTask类具有N属性
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#define SIZE 4096
typedef struct s_stack
{
int capacity;
int count;
int top;
char *list[SIZE];
} t_stack;
char *up(t_stack *stack)
{
if (stack->count == 0)
return (stack->list[0]);
return (stack->list[stack->count--]);
}
char *down(t_stack *stack)
{
if (stack->count > stack->top)
{
stack->count = stack->top;
return ("");
}
if (stack->count < stack->top)
return (stack->list[stack->count++]);
return ("");
}
void create_stack(t_stack *stack)
{
memset(stack->list, 0, SIZE);
stack->count = -1;
stack->top = -1;
stack->capacity = SIZE;
}
void push(t_stack *stack, char *value)
{
if (stack->top == stack->capacity - 1)
return ;
stack->list[++stack->top] = value;
}
int main()
{
t_stack stack;
create_stack(&stack);
push(&stack, "1");
push(&stack, "2");
push(&stack, "3");
push(&stack, "4");
push(&stack, "5");
push(&stack, "6");
push(&stack, "7");
push(&stack, "8");
push(&stack, "9");
push(&stack, "10");
stack.count = stack.top;
while (1)
{
int ret;
char buf[4];
ret = read(0, buf, 4);
if (buf[0] == 'u')
printf("%s\n", up(&stack));
else if (buf[0] == 'd')
printf("%s\n", down(&stack));
else
break ;
}
return 0;
}