memory corruption

#include "mathalizer.h"


int multiply(int x, int y)
{
return x*y;
}

int add(int x, int y)
{
return x+y;
}

int ** create_table(int size, int (* oper) (int,int))
{
int x;
int y;
int **array;
if(size<1) return NULL;
array = (int **)malloc(size*sizeof(int*));
if(array==NULL) return 1;

for(x=0;x {
array[x]=(int*)malloc(size*sizeof(int));
}

for(x=0;x {
for(y=0;y {
array[x][y]=(* oper)(x,y);
}
}

return array;
}

int save_table(FILE * fp, int ** array, int size)
{
int x;

for(x=0;x {
fwrite(array[x],sizeof(int),size,fp);
}
fclose (fp);

return 1;
}

int ** load_table(FILE * file, int size)
{
int x;
int fread_return_code_2;
int **array2;
array2 = (int **)malloc(size*sizeof(int*));
if(array2==NULL) return 1;

for(x=0;x {
array2[x]=(int*)malloc(size*sizeof(int));
}

for(x=0;x {
fread_return_code_2=fread(array2[x],sizeof(int),size,file);
}
if(fread_return_code_2!=size) return 1;
fclose(file);

return array2;
}

2 comments:

  1. Its great to see a Nagpur based institute having a great initiative !!

    Best Regards from me !!

    ReplyDelete
  2. Thank Friend....Try New Site www.glearn.net

    ReplyDelete