GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Wed Jul 23, 2014 5:36 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: g_print to write to a file
PostPosted: Tue Aug 21, 2012 10:44 pm 
Offline
GTK+ Guru

Joined: Sun Jul 08, 2012 3:14 pm
Posts: 107
Location: Coventry, UK
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?


Top
 Profile  
 
 Post subject: Re: g_print to write to a file
PostPosted: Wed Aug 22, 2012 8:16 am 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hi.

The simplest solution here is to simply use fprintf() from standard C library (or g_fprintf() from GLib). More complicated way of dealing with this would be to call g_set_print_handler() and then redirect messages to file.

Cheers,
Tadej


Top
 Profile  
 
 Post subject: Re: g_print to write to a file
PostPosted: Thu Aug 23, 2012 3:44 am 
Offline
Never Seen the Sunlight

Joined: Thu Mar 24, 2011 2:10 pm
Posts: 328
Location: Sydney, Australia
I find g_file_set_contents(const gchar *filename, const gchar *contents, gssize length, GError **error); to be the most convenient. Other glib file handling functions can be found at http://developer.gnome.org/glib/2.33/glib-File-Utilities.html.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group