I'm learning c not really fully understand everything, i have this example code i gat from a book. The Topic is the usage of calloc() and realloc().I'm using Ubuntu 14.04 and the gcc compiler. I checked on the syntax in the code and is just the same as in the book didn't make any mistakes. So what i think the problem is, is how to write the code so that the compiler understands it the way it needs it. For that i do not have the experience to figure that out. I have more error outputs if needed.
#include<stdio.h>
#include<stdlib.h>
void main(){
double * memptr;
memptr = (double *) calloc(100, sizeof(double));
if (memptr == NULL){
printf("\nNicht genuegend Speicherplatz!");
exit(1);
}
printf("\nSpeicher fuer 100 double-Variable Ok!");
memptr = (double*) realloc(memptr,125);
if(memptr ==NULL){
printf("\nNicht genuegend Speicherplatz!");
exit(1);
}
printf("\nSpeicherplatz auf 125 Variable vergroessert!");
free(memptr);
printf("\nSpeicher wieder freigegeben!");
}
Error messages:
*bei84.c: In function ‘main’:
bei84.c:7:22: warning: incompatible implicit declaration of built-in function ‘calloc’
[enabled by default]
memptr = (double *) calloc(100, sizeof(double));
^
bei84.c:13:21: warning: incompatible implicit declaration of built-in function ‘realloc’
[enabled by default]
memptr = (double*) realloc(memptr,*125);