Hello, everyone. I'm trying to implement a stack using the following struct:
Then, arrayOfStrings will contain strings. My idea is to use the following function to initialize it with as an empty array of strings, and then use realloc everytime a new element is to be added to the stack:
This last statement is just there to help me check if the stack is indeed empty. However, it prints 4, instead of 0. What am I doing wrong in this function? Thanks in advance!
Code:
typedef struct stackOfStrings { char **arrayOfStrings; } StackOfStrings;
Code:
void initializeStackOfStrings( StackOfStrings *s ) { s->arrayOfStrings = ( char ** )malloc( 1 * sizeof( char * ) ); *( s->arrayOfStrings ) = ( char * )malloc( 0 * sizeof( char ) ); printf( "%d\n", sizeof( s->arrayOfStrings ) ); }
Comment