These are errors:
*num = rand() % 1300 + 1201 / 100.00;
*num
is in the [12.01, 1311.01] range. If you need a number in the [12.01, 13.00] range, change the assignment:
*num = 12.01 + (rand() % 100) / 100.0;
printf("%f", num);
should be printf("%f", *num);
Also it's a good idea to enable extra warnings during compilation. E.g. with -Wall -Wextra
clang -Wall -Wextra filename.c
warning: format specifies type 'double' but the argument has type 'float *' [-Wformat]
Same with gcc
gcc -Wall -Wextra filename.c
warning: format '%f' expects argument of type 'double', but argument 2 has type 'float *' [-Wformat=]
If you are playing with malloc
/free
you should check for allocation failures.
Memory allocation is not guaranteed to succeed, and may instead return a null pointer. If there's no check for successful allocation implemented, this usually leads to a crash of the program, due to the resulting segmentation fault on the null pointer dereference.
So you could change your code in this way:
float *num = malloc(sizeof(float));
if (num)
{
// your code
}
else
{
// handle failure
}
Anyway it's better to just use a simple float.