open an existing file in buffer and write on it

2013-01-25 Thread Rudra Banerjee
Dear friends, as evident from my last few posts, I am struggling with opening a file as buffer and write to it (guess it has *nothing* to do with gtk, but C. Still I will be grateful if you people kindly help). So, first, how to open file in buffer? /* Files opened and edited directly*/ /* FILE

Re: open an existing file in buffer and write on it

2013-01-25 Thread zz
On Friday 25 January 2013 14:57:23 Rudra Banerjee wrote: > Dear friends, > as evident from my last few posts, I am struggling with opening a file > as buffer and write to it > (guess it has *nothing* to do with gtk, but C. Still I will be grateful > if you people kindly help). > So, first, how to

Re: open an existing file in buffer and write on it

2013-01-25 Thread Rudra Banerjee
ZZ, thanks for your comment! But is it so tough? database and all that? All I want to do is to have the ability of editing an existing file. Since directly editing the file is not recommended, this is the reason why I want to open it as buffer! On Fri, 2013-01-25 at 16:10 +0100, z...@excite.it wro

Re: open an existing file in buffer and write on it

2013-01-25 Thread Damien Caliste
Hello, Le 25/01/2013, Rudra Banerjee a écrit : > But is it so tough? database and all that? For managing several bibliography files, that should be better yes. > All I want to do is to have the ability of editing an existing file. > Since directly editing the file is not recommended, this is the

Re: open an existing file in buffer and write on it

2013-01-25 Thread Colomban Wendling
Le 25/01/2013 17:02, Damien Caliste a écrit : > [...] > > The idea when you want to change a file on disk is (not too big) : > - generate a buffer of the full content of the file in memory, using > GString for instance > (http://developer.gnome.org/glib/unstable/glib-Strings.html) since > th

Re: open an existing file in buffer and write on it

2013-01-25 Thread Rudra Banerjee
Hi Damien, Thanks for your reply. What I have ended up with is something like: FILE *fopf = fopen(filename, "a" ); if (!fopf){ filename="Untitled.bib"; fopf= fopen(filename,"a"); } char buffer[]="Hello World"; int buf_size= strlen(buffer)+1; fwrite(buffer,buf_size,1,fopf); if(

Re: open an existing file in buffer and write on it

2013-01-25 Thread Andrew Potter
On Fri, Jan 25, 2013 at 9:00 AM, Rudra Banerjee wrote: > But this writes the data in unformatted form. > Can you kindly explain a bit more? > > A good tool glib has for serializing data is GVariant: http://developer.gnome.org/glib/stable/glib-GVariant.html All the example below is untested, so if

Re: open an existing file in buffer and write on it

2013-01-25 Thread Liam R E Quin
On Fri, 2013-01-25 at 10:44 -0800, Andrew Potter wrote: > [...] > You can get a nice buffer of "binary data" to write to file: Please let's not encourage the use of binary file formats where there's no measured performance requirement. An XML file would be better if structure is needed, as then i

Re: open an existing file in buffer and write on it

2013-01-25 Thread Andrew Potter
On Fri, Jan 25, 2013 at 11:00 AM, Liam R E Quin wrote: > Please let's not encourage the use of binary file formats where there's > no measured performance requirement. An XML file would be better if > structure is needed, as then it can be interchanged with other tools and > platforms, and the fi

Re: open an existing file in buffer and write on it

2013-01-25 Thread Andrew Potter
On Fri, Jan 25, 2013 at 11:14 AM, Andrew Potter wrote: > [...] blah blah blah. > On second reading this comes off as a little flippant, my apologies. You made a good point, and I should have prefaced my example with links to "proper" serialization tools. __

Re: open an existing file in buffer and write on it

2013-01-25 Thread Liam R E Quin
On Fri, 2013-01-25 at 11:45 -0800, Andrew Potter wrote: > On Fri, Jan 25, 2013 at 11:14 AM, Andrew Potter wrote: > > > [...] blah blah blah. > > > On second reading this comes off as a little flippant, my apologies. > You made a good point, and I should have prefaced my example with links to > "p

Re: open an existing file in buffer and write on it

2013-01-25 Thread David Nečas
On Fri, Jan 25, 2013 at 04:25:53PM -0500, Liam R E Quin wrote: > That it's easier for the programmers to create and read > application-specific binary files is a problem that would be worth > fixing. Probably you mean replacing it with the problem of application-specific hodge podge XML... I have

Re: open an existing file in buffer and write on it

2013-01-25 Thread Liam R E Quin
On Sat, 2013-01-26 at 00:06 +0100, David Nečas wrote: > On Fri, Jan 25, 2013 at 04:25:53PM -0500, Liam R E Quin wrote: > > That it's easier for the programmers to create and read > > application-specific binary files is a problem that would be worth > > fixing. > > Probably you mean replacing it w

Re: open an existing file in buffer and write on it

2013-01-28 Thread Damien Caliste
Hello, Le 25/01/2013, Rudra Banerjee a écrit : > What I have ended up with is something like: > FILE *fopf = fopen(filename, "a" ); > if (!fopf){ > filename="Untitled.bib"; > fopf= fopen(filename,"a"); > } > char buffer[]="Hello World"; > int buf_size= strlen(buffer)+1; > fwri

Re: open an existing file in buffer and write on it

2013-01-29 Thread Rudra Banerjee
I tried a lot(trying to understand the huge GLib as suggested by Andrew), but most of the discussion here went way beyond my capability. So, lets try from fresh. My code for treeview and editing the treeview column (column Id #1). So, once the column is edited, its updated by the cell_edited. Now

Re: open an existing file in buffer and write on it

2013-01-30 Thread zz
On Tuesday 29 January 2013 22:47:57 Rudra Banerjee wrote: > I tried a lot(trying to understand the huge GLib as suggested by > Andrew), but most of the discussion here went way beyond my capability. > So, lets try from fresh. > > My code for treeview and editing the treeview column (column Id #1).