So my code is creating a pointer to an array with 80 rows. Say the user supplied 10 in the command line argument, he wanted the stack to have 10 rows. malloc would find memory space for 800 bytes, since 10 rows of potentially 80 bytes each would be 800. So then would I create an array of size 10 and point it to the malloc space I just allocated? Something like this?
Code:
int main(int argc, char *argv[])
{
char (*aa)[80];
int stackSize;
stackSize = atoi(argv[1]);
aa = malloc(stackSize * 80);
char bb[stackSize];
aa = bb;
}
I am still confused with the '80' in char (*aa)[80] however. Why does aa even need to be an array if it is just going to be pointing to a 800 byte location of memory?
edit: more thinking...
Code:
char (*aa)[80];
int stackSize;
stackSize = atoi(argv[1]);
// error checking omitted
aa = malloc(stackSize * 80);
char (*bb)[stackSize];
bb = aa;
So if stackSize was 10, then aa would point to a memory location of 800 bytes, bb would be created to point to an array of size 10, and then that array would be pointed to the allocated 800 bytes worth of memory.