I need to write a program that will allocate the memory for multiplication table. The problem is that single call of malloc, calloc and realloc is limited to 80 bytes and I don't know how to allocate memory stage by stage. If anyone could help me I would be grateful.
Here is what I have tried already. It works if I allocate the memory for 400 bytes in one call.
int main()
{
int row = 10;
int col = 10;
int w=0;
int k=0;
int *tab = (int *)malloc(row*col*sizeof(int));
if(tab == NULL)
{
printf("Failed to allocate memory");
return 8;
}
int i=0;
for (w=0; w<row; w++)
{
for(k=0; k<col; k++)
{
*(tab+w*col+k) = ++i;
}
}
for (w=0; w<row; w++){
for(k=0; k<col; k++){
printf("%3d ", *(tab+w*col+k) );
}
printf("\n");
}
free(tab);
return 0;
}