Re: write to a file using g_print



Thanks! Its working excellent.
Now, I have another small problem.
I have opened a file from the menubar filechooser dialog as:

static void open_file(GtkWidget *widget, gpointer data) {
    GtkWidget *dialog;//, *entry;
    dialog = gtk_file_chooser_dialog_new("Open File",
            GTK_WINDOW(window),
            GTK_FILE_CHOOSER_ACTION_OPEN,
            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
            GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
            NULL);
    if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
        char *filename;
        filename =
gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
        read_view(filename);
        g_print(filename);
    }
    gtk_widget_destroy(dialog);
}

I would like to append this file from another function:
static void
activate_func(GtkWidget *widget, gpointer data) {
/* OTHER STAFF */
FILE *fop = fopen("file.bib", "a" );
    g_fprintf( fop, "@%s{%s,\n", strcombo, strkey );
/*ETC*/
}

instead of fopen("file.bib","a"), I tried fopen(open_file( *widget,
data,filename),"a") and also adjusted the argument of open_file.
but its not working. 

How I can transfer the filename from open_file to activate_func?
On Wed, 2012-08-22 at 07:45 +0800, Ardhan Madras wrote:
g_open() is wrapper to open() syscall, not the standard libc's fopen().

mkbib.c:114:15: warning: initialization makes pointer from integer
without a cast [enabled by default]
You got this because g_open() returning a int (file descriptor) not a
FILE pointer.

You must distinguish each I/O method that you are using and don't mess with it.
You can't use a file descriptor to standard libc's I/O functions, use
FILE pointer instead.

#include <glib.h>
#include <glib/gstdio.h>
#include <stdio.h>

FILE *fop = open("bib2.bib", "w");
/* you can call g_fprintf() or fprintf() */

see man 3 printf

Is it possible to write to a file using g_print?
g_print() already write to standard output FILE, but you can dup()
standard output to another file.

Regards.

On Wed, Aug 22, 2012 at 6:42 AM, Rudra Banerjee <bnrj rudra yahoo com> wrote:
Is it possible to write to a file using g_print?
I was trying something like:

  FILE *fop = g_open("bib2.bib","w");
  g_print ("%s%s",strcombo,strkey, fop);

but its not working.
Even fprintf is giving warning and not writing.
mkbib.c:114:15: warning: initialization makes pointer from integer
without a cast [enabled by default]
mkbib.c:115:3: warning: passing argument 1 of âfprintfâ from
incompatible pointer type [enabled by default]

Any solution?


_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]