When allocating memory, specify the size of the allocation:
int array_length = 100; int *array = (int*) malloc(array_length * sizeof(int)); char *array = (char*) malloc(array_length * sizeof(char));