LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   C GTK+: String returned by gtk_file_chooser_get_filename gives segmentation fault (https://www.linuxquestions.org/questions/programming-9/c-gtk-string-returned-by-gtk_file_chooser_get_filename-gives-segmentation-fault-836190/)

youarefunny 10-04-2010 06:54 PM

C GTK+: String returned by gtk_file_chooser_get_filename gives segmentation fault
 
My program gives a segmentation fault when fputs 'ing the filename. Why is that? ( fopen works like a charm )

Code:

void change_port ( void )
{
    if ( port != NULL )    fclose(port);    //    If it is already open close it

    char *fname = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(port_select));


    fflush(stdout);

    port = fopen(fname, "r+");

    if ( port == NULL )
    {
        error("Error Opening Port: ");
        error(fname);
        error("\n");
    }
}

void error ( char *msg )
{
    fputs(msg, stderr);

    fflush(stderr);
}


ananas 10-05-2010 05:59 AM

check fname for NULL

youarefunny 10-05-2010 04:50 PM

Thank you. Now is feel dumb. I have solved why this is happening. Thank you very much.


All times are GMT -5. The time now is 04:34 PM.