Re: write to a file using g_print

2012-08-22 Thread Rudra Banerjee
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 
> #include 
> #include 
> 
> 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  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


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

Re: write to a file using g_print

2012-08-22 Thread Ardhan Madras
> How I can transfer the filename from open_file to activate_func?

When the activate_func() will be invoked? is it a callback function or
something?. I don't know why and how you implemented that, but you
already retrieved filename in open_file(), if you supposed to call
activate_func() here, you can pass the filename to activate_func(),
the activate_func() much or less will be;

static void activate_func(const char *filename)
{
   FILE *fop = fopen(filename, "a" );
   /* Verify and work with it */
}

then call activate_func(filename) in open_file()

> 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.

You can't fopen(open_file( *widget, data,filename),"a") because it is
a programming error, peoples in this list usually will not happy to
answer this.

Regards


On Wed, Aug 22, 2012 at 7:42 PM, Rudra Banerjee  wrote:
> 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?
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list