arrays dimensioning: malloc and sizeof
I'm not sure whether I'm doing this wrong or sizeof can't read arrays dimensioned with the memory allocation functions. Here's what I have:
Code:
#include <stdio.h>
#include <stdlib.h>
void main()
{ char *NEW_ARRAY;
char NEW_ARRAY2[5];
NEW_ARRAY = malloc(5 * sizeof(char));
if(NEW_ARRAY != NULL)
{ printf("%d\n", sizeof(NEW_ARRAY));
printf("%d\n", sizeof(NEW_ARRAY2));
}
free(NEW_ARRAY);
}
NEW_ARRAY returns 4 (no matter what I put in as the MALLOC size value)
NEW_ARRAY2 returns the correct number of 5 positions within the array.
Any ideas? The solution I'm using this in pulls characters from a static array. The amount of characters it pulls varies so I need to create a dynamic container character array.