BIGINT를 보유 할 스택이 있습니다. bigint는 숫자와 다른 값을 보유 할 char 배열을 가진 구조체입니다. 그래서 스택을 만들었고 모든 것이 STDIN에서 잘 작동했지만 bigint를 추가하려고하면 아무 것도 추가되지 않는 것처럼 보입니다. 지금스택에 포인터를 추가 C
struct bigint {
size_t capacity;
size_t size;
bool negative;
char *digits;
};
bigint *new_string_bigint (char *string) {
assert (string != NULL);
size_t length = strlen (string);
bigint *this = new_bigint (length > MIN_CAPACITY ? length : MIN_CAPACITY);
char *strdigit = &string[length - 1];
if (*string == '_') {
this->negative = true;
++string;
}
char *thisdigit = this->digits;
while (strdigit >= string) {
assert (isdigit (*strdigit));
*thisdigit++ = *strdigit-- - '0';
}
this->size = thisdigit - this->digits;
trim_zeros (this);
return this;
}
그리고 스택 내 additon :
다음struct stack {
size_t capacity;
size_t size;
stack_item *data;
};
내 bigint
구조 :
void push_stack (stack *this, stack_item item) {
if (full_stack (this)){realloc_stack (this);}
this->data[this->size] = strdup(item);
this->size++;
}
내 stack
구조 : 여기 내 push_stack()
코드는
void do_push (stack *stack, char *numstr) {
bigint *bigint = new_string_bigint (numstr);
show_bigint(bigint);
push_stack(stack, bigint);
}
어떤 이유로 든 bigint
은 스택에 추가되지 않습니다. 어떤 도움을 주셔서 감사합니다.
왜냐하면 나는 strdup을 사용하고 있기 때문입니까? – user1924782
스택 정의를 포함하지 않았습니다 –
'stack_item '이란 무엇입니까? 0으로 끝나는 문자열에'char * '가 없으면 그것을'strdup()'할 수 없습니다. – John3136