I'm having some troubles with pointers.
This is their declaration (in main):
int *dot_positions = (int *)malloc(sizeof(int));
char *str = (char *)malloc((MAX_N + 1) * sizeof(char));
Where MAX_N is 100, and is the limit of the string. dot_positions[0] = -1;
I add a value to the first position of 'dot_position', then, in runtime, I call the following function in order to add other values.
int add_dot_to_array(int *array, int position, int array_len) {
array = (int *)realloc(array, array_len + 1);
array[array_len] = position;
return array_len + 1;
}
At the end of the main(), I free the pointers:
free(str);
free(dot_positions);
But this causes the crash of my program. I'm using Orwell Dev-C++ with Mingw on a Windows x64 machine. I'm also sure that those pointer are not NULL. What's wrong? Thanks in advance!