Fread () fallido de int almacenado en archivo binario, fallo de segmentación [cerrado]

Parece haber del orden de 10 preguntas y (en su mayoría) respuestas exitosas que resuelven fallas de segmentación causadas por el uso indebido de fread () en C. Dicho esto, estoy teniendo ese problema pero no he encontrado una solución.

Tengo un archivo binario que contiene unint (llámalonbins) y una serie defloats (de tamañonbins) Cuando intento leer este archivo, se abre con éxito y apunta al identificador del archivo, pero luego da un error de segmentación al leer el archivonbins int. Aquí hay un ejemplo mínimo:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define BPATH "/path/to/file"

int main(int agrc, char **argv)
{
    FILE *fd;
    int num;
    char fname[500]={};

    int nbins;
    float *coords;

    num = 5;
    sprintf(fname,"%s/file%d.dat", BPATH, num);

    if(!(fd=fopen(fname,"rb")))
    {
        printf("Can't open file: %s\n\n",fname);
        exit(0);
    }    

    printf("Reading input file:\n");
    printf("%p: %s\n", fd, fname);       // prints successfully

    fread(&nbins, sizeof(int), 1, fd);   
    printf("nbins = %d", nbins);         // seg faults before this print

    /* EDIT: the above print isn't properly flushed without an \n    
     * The seg fault was not caused by the fread(), but the lack of  
     * the above print lead to the confusion                         */

    coords = malloc(nbins * sizeof(float));
    fread(coords, sizeof(float), nbins, fd);

    fclose(fd);
    free(coords);

    return(0);
}

El archivo fue creado con el siguiente formato:

int nbins[1];
nbins[0] = 5;                          // this 5 is just an example...
fwrite(nbins, sizeof(int), 1, file_ptr);
fwrite(coords, sizeof(float), nbins[0], file_ptr);

También he intentado usar:

int *nbins = malloc(sizeof(int));
fread(nbins, sizeof(int), 1, fd);

Pero esto no resolvió el problema. El archivo existe y es legible; Puedo leerlo bien usando Python, con NumPy'sfromfile(). ¿Me estoy perdiendo algo obvio? ¡Gracias!

Respuestas a la pregunta(1)

Su respuesta a la pregunta