0
Has anyone ever used the calloc and realloc commands in C
I'm having a hard time incorporating these two into a stack program I'm writing. Any suggestions welcomed.
6 Réponses
+ 4
use the realloc when you add an element and the stack is full
but I do not see the use of calloc instead of malloc, is there a particular reason ?
+ 3
Yes @Ace, I know this use but I do not know why a stack should be zero filled as a block is considered empty if the user do not add its own element in it
+ 2
Yes I have ! What is your problem ? :)
edit : you should tag this post in C not C#
+ 1
It will depend on your implementation of the of stack. If (in the background) it is a dynamically allocated array you can resize it using realloc.
If it works like a linked list, then you can add new nodes (data blocks) to the list using calloc (or malloc).
I cannot give any more detailed without knowing your data structures and functions.
0
the program itself I have running it's a simple stack. It ask the user is they would like to push, pop or display what's in the stack which all work fine. The program also tells the users when the stack if full and empty. But I want to use realloc and calloc to make the stack bigger if full on the go but don't know how to incorporate them into the code.