project/weight.c
/**
 * Loads JSON file into buffer.
 */
Loads JSON file into buffer.
Loads JSON file into buffer .
void loadFile(char* filename)
{
  FILE *fp;
  long lSize;
  char *buffer;
  fp = fopen(filename, "rb");
  if (!fp)
  {
    perror(filename);
    exit(1);
  }
  fseek(fp, 0L, SEEK_END);
  lSize = ftell(fp);
  rewind(fp);
  buffer = calloc(1, lSize + 1);
  if (!buffer)
  {
    fclose(fp);
    fputs("memory alloc", stderr);
    exit(1);
  }
  if (1 != fread(buffer, lSize, 1, fp))
  {
    fclose(fp);
    free(buffer);
    fputs("read", stderr);
    exit(1);
  }
  fclose(fp);
  readFile(buffer);
  free(buffer);
}
void loadFile ( char * filename ) { FILE * fp ; long lSize ; char * buffer ; fp = fopen ( filename , " " ) ; if ( ! fp ) { perror ( filename ) ; exit ( 1 ) ; } fseek ( fp , 0L , SEEK_END ) ; lSize = ftell ( fp ) ; rewind ( fp ) ; buffer = calloc ( 1 , lSize + 1 ) ; if ( ! buffer ) { fclose ( fp ) ; fputs ( " " , stderr ) ; exit ( 1 ) ; } if ( 1 != fread ( buffer , lSize , 1 , fp ) ) { fclose ( fp ) ; free ( buffer ) ; fputs ( " " , stderr ) ; exit ( 1 ) ; } fclose ( fp ) ; readFile ( buffer ) ; free ( buffer ) ; }
Loads JSON file into buffer.
Loads JSON file into buffer .
//printf("-----loadFile()-----\n"); // allocate memory // copy file into buffer