fread / _gcvt



  • Ich habe ein Problem, bei dem ich nicht weiterkomme. Ich lese aus einer Datei Daten ein (floats) - das dumme ist, dass sich die app sang und klanglos beendet, wenn ein bestimmtes Byte mit in dem Wert enthalten ist (0x1A).

    float f(0.0f);
    	fread(&f, sizeof(float), 1, in);
    	_gcvt((double)f, 7, buffer);
    

    Das Problem an sich ist bekannt:

    http://sources.redhat.com/ml/cygwin/1999-09/msg00155.html

    I'm trying to scan binary files (log files of serial i/o, contains lists of
    binary messages with header,tail, and timestamp) with the awk - program. The
    awk-script does what I want. The only problem I detect is, if a 0x1a - Byte
    occurs within the input file this is interpreted as a premature end of file
    ! I know, the awk program is for text-file scanning. Therefore : is there
    any other possibility to scan such binary files for byte-patterns without
    programming such tool by myself ?

    Aber ich konnte keine Lösung dazu finden... wenn ich die 0x1A Werte kille verändern sich ja logischer Weise die Werte.

    edit: 0x1A ist imho der eof-Wert. Deshalb der Abbruch ohne error etc.
    edit2: Man könnte eventuell auf feof() verzichten und einfach den Error beim Einlesen abfangen...?



  • feof() durch ferror() erstetzen geht - aber die Werte stimmen nicht 😞



  • <Kristallkugel>vielleicht solltest du die Datei im Binärmodus öffnen</Kristallkugel>



  • Die Werte stimme leider immernoch nicht 😕

    in = fopen("FZSTAMM.D0A", "rb");
    float f(0.0f);
    fseek(in, t+tab[j][0], SEEK_SET);
    fread(&f, sizeof(float), 1, in);
    _gcvt((double)f, 7, buffer);
    fwrite(buffer, sizeof(char), strlen(buffer), out);
    fclose(in);
    

    Mach ich im Code was falsch?

    edit: [code-einrücken]
    edit2: Komisch, hier hats geholfen: http://www.c-plusplus.net/forum/viewtopic.php?t=32011&highlight=0x1a


Anmelden zum Antworten