ERLEDIGT: Mit fscanf ein short int lesen?



  • Hallo,

    versuche mich gerade an C und blicks nicht^^

    Folgendes funktioniert:

    char in = 0; /* 1 Byte */
    fprintf(stdout, "%ld: %#x %d\n", ftell(f[1]), in, fscanf(f[1], "%c", &in));
    

    Ich muss aber 2 Byte also ein short int auslesen.
    Das funktioniert so nicht:

    short int in = 0; /* 2 Byte */
    fprintf(stdout, "%ld: %#x %d\n", ftell(f[1]), in, fscanf(f[1], "%hd", &in));
    

    Was ist der Fehler und wie wäre es korrekt 😕

    LG mabu82



  • fscanf ist trotz fopen mit rb nicht binär - das war der fehler.

    short int in = 0; /* 2 Byte */
    fprintf(stdout, "%ld: %#x %d\n", ftell(f[1]), in, fread(&in, 2, 1, f[1]));
    

Anmelden zum Antworten