Reputation: 107
So, I get this error in C function.
Variables:
int* first_array = (int*) malloc(0);
int first_array_length;
int* second_array = (int*) malloc(0);
int second_array_length;
// Setting up first array
set_up_array(first_array, &first_array_length);
And this is a function:
void set_up_array(int *arr, int *num)
{
char lenght_msg[] = "Iveskite masyvo ilgi";
char value_msg[] = "Iveskite masyvo elementa";
*num = num_scan(0, MAX_SIZE, lenght_msg);
arr = (int*) realloc(arr, num * sizeof(int)); // <- error here
for (int i = 0; i < (*num); i++)
{
arr[i] = num_scan(INT_MIN, INT_MAX, value_msg);
}
}
Please, help!
Error:
invalid operands of types 'int*' and 'unsigned int' to binary 'operator*'|
Upvotes: 0
Views: 4661
Reputation: 145829
Use *num
instead of num
in:
realloc(arr, num * sizeof(int));
num
is a pointer to int
, the value of the int
pointee is *num
.
And you should not cast the realloc
return value.
http://c-faq.com/malloc/mallocnocast.html
Upvotes: 3