dimanche 26 juin 2016

Loading and writing binary files using gtk3 in c

I am building an app to analyse scientific data using . I am unable to load binary files and create new binary with some part of the content from the read file.

I used GFileoutputStream and g_file_load_contents but as soon as zero comes it takes it as terminating character which i don't want. I want to read even zeros and then extract data bit wise. Any help would be highly appreciated.

My code:

 void file_selected(GtkWidget *filechooserbutton, gpointer data, GtkTextBuffer *buffer) {   
    filename=gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(filechooserbutton));
    g_file_get_contents(filename, &contents, NULL, NULL);

    text1 = g_substr(contents,0,value);     

    gint DataHeaderNum=96;
    gint value2=value+DataHeaderNum;
    text2 = g_substr(contents,value,value2);        

    gchar *filler;
    filler=g_strnfill (DataHeaderNum,'0');
    //g_print(filler);
    gint DataNum=2048-DataHeaderNum;
    gint value3=value2+DataNum;
    text3 = g_substr(contents,value,value3);
    g_strlcat(filler,text3,2048);
    text3=g_strdup(filler);
    //g_print(text3);


    gchar *full;
    gchar *name="SpaceCraftHeader";
    gchar *name2="DataHeader";
    gchar *name3="Data";

    full=g_strdup(filename);
    g_strlcat(full,name,50);

    GFile *file=g_file_new_for_path(full);
    GFileOutputStream *output=g_file_replace(
                file,NULL,FALSE,
                G_FILE_CREATE_NONE,
                NULL,NULL);

    g_output_stream_write(G_OUTPUT_STREAM(output),
                text1,strlen(text1),NULL,NULL);

    g_output_stream_close(G_OUTPUT_STREAM(output),NULL,NULL);


}

Aucun commentaire:

Enregistrer un commentaire