LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-08-2011, 01:36 AM   #1
on_a_work
LQ Newbie
 
Registered: Jan 2011
Posts: 7

Rep: Reputation: 0
Question exporting glade text view to text file


I want to display something in my text view widget in glade using c code. that's all right.
now I need to attach a save button beneath the text view.so that on click the text view content should save as a txt file...possible?..any idea?
 
Old 01-08-2011, 04:33 PM   #2
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,630
Blog Entries: 3

Rep: Reputation: 345Reputation: 345Reputation: 345Reputation: 345
What are you stuck with? As far as I was aware, Glade just creates the files for you, you need to code all the writing etc. yourself in C. So if you have added the button, then writing to a file on the disk just a matter of using some stdio.h functions...
 
Old 01-08-2011, 08:49 PM   #3
on_a_work
LQ Newbie
 
Registered: Jan 2011
Posts: 7

Original Poster
Rep: Reputation: 0
i think there is some code for catching the contents of text view line by line and saving as a text file..ah?
 
Old 01-09-2011, 04:53 AM   #4
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,630
Blog Entries: 3

Rep: Reputation: 345Reputation: 345Reputation: 345Reputation: 345
Given you've told us nothing about your code, I'm guessing you're using the Entry Widget, in which case a call to
Code:
const gchar *gtk_entry_get_text( GtkEntry *entry );
will get you the text inside it and then can be written to a file just like any string in C.
 
Old 01-11-2011, 05:36 AM   #5
on_a_work
LQ Newbie
 
Registered: Jan 2011
Posts: 7

Original Poster
Rep: Reputation: 0
hope it will make a diffrence!!!thank you
 
Old 01-11-2011, 05:48 AM   #6
on_a_work
LQ Newbie
 
Registered: Jan 2011
Posts: 7

Original Poster
Rep: Reputation: 0
can i export the text into text file?i need to make text files in different names in diffrent execution
 
Old 01-11-2011, 06:20 AM   #7
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,630
Blog Entries: 3

Rep: Reputation: 345Reputation: 345Reputation: 345Reputation: 345
Yes... I assume you mean "write" to a text file, and if so, it can be done as follows:

Code:
#include <stdio.h>

void main(){
    FILE *fp;
    fp = fopen("outputfile",'w');
    fprintf(fp,"Well, there's egg and bacon; egg sausage and bacon;\n egg and spam; egg bacon and spam; egg bacon sausage and spam;\n spam bacon sausage and spam; spam egg spam spam bacon and spam; spam sausage spam spam bacon spam tomato and spam...\n");
    fclose(fp)
}
 
Old 01-12-2011, 09:10 PM   #8
on_a_work
LQ Newbie
 
Registered: Jan 2011
Posts: 7

Original Poster
Rep: Reputation: 0
i know that code.but i need to create new file everytime.its like a log file.names should be different each time so that files not get overwritten.
 
Old 01-13-2011, 09:05 AM   #9
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,395
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
A common approach to this problem is to make filenames containing time & date components. As long as there is only one instance of the program running, and the timestamp used is finely enough resolved, the names are guaranteed to be unique, and also have the benefit of carrying potentially useful information. With carefully chosen formats, they can also sort nicely.

For the basic information,

man ctime

--- rod.

Last edited by theNbomr; 01-13-2011 at 09:07 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to parse text file to a set text column width and output to new text file? jsstevenson Programming 12 04-23-2008 02:36 PM
View Chinese character in text file using vi ufmale Red Hat 1 02-17-2008 01:05 PM
How to parse log files into text view using GLADE shandy^^^ Programming 8 02-07-2006 08:13 PM
View Line In Text File DaveyB Programming 1 11-03-2004 12:02 PM
view text file in hex under kdevelop tcma Linux - Software 1 10-20-2004 05:57 PM


All times are GMT -5. The time now is 04:59 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration