Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 10-26-2011, 07:09 AM   #1
LQ Newbie
Registered: Oct 2011
Posts: 25

Rep: Reputation: Disabled
just curious whether this can be done or not

hey everyone,
i am interested to do this.I am not sure whether it can be done or not.That's why i decided to post this thread for seeking ideas and helps.
This is what i am trying to do.The idea is to create a text file using c or c++ program and called the text file to the web page.I succeed to output the text file in the web page.But now I wish to output the output in the text file in a table(table similar to HTML table which have column and row)

For example my output in text file is something like this:

2pm Henry 25
3pm Mark 20

What i wish is to create a table and put these output into it...
This is what i wish to do..
For example the table has 3 columns and 2 rows..
1st column is time,2nd is Name and the 3rd is age...
I want to enter the output of text file such as 2pm Henry 25 to the specific column.For example 2pm to time,Henry to name and 25 to age...Hope someone can give ideas and info...thanks in advanced
Old 10-26-2011, 07:15 AM   #2
Senior Member
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 650Reputation: 650Reputation: 650Reputation: 650Reputation: 650Reputation: 650
You may as well just have your c++ code output html markup in the text document, or another option may be to output xml and have an xslt generate the table and other code.
Old 10-26-2011, 07:46 AM   #3
LQ Newbie
Registered: Oct 2010
Posts: 14

Rep: Reputation: 0
thanks mate...but could u give me some source to read....mybe some web pages since i didn't quite get what u told me...i am sorry as i am a noob..but i want to read it if u have some tutorials or something..thanks in advanced...

Last edited by nikhidet; 10-26-2011 at 07:49 AM.
Old 10-26-2011, 08:31 AM   #4
Senior Member
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 650Reputation: 650Reputation: 650Reputation: 650Reputation: 650Reputation: 650
Sorry, looking back maybe I misread your first post - do you want a text file where the data is laid out in a table or did you want an actual html table?

For the first, you probably want to pad each field with spaces so they're all the same width then add a tab between each field.
#include <iomanip>

cout << setw(15) << mytime << "\t" << setw(15) << myname << "\t" << setw(15) << myage << endl;
For html output:
cout << "<table><th>Date</th><th>Name</th><th>Age</th>" << endl;
  cout << "<tr><td>date</td><td>name</td><td>age</td></tr> << endl;
The examples are illustrative more than usable
Old 10-27-2011, 07:48 AM   #5
LQ Newbie
Registered: Oct 2011
Posts: 25

Original Poster
Rep: Reputation: Disabled
thanks....really appreciate it...first of all,this is my plan...
for example i have a c program that will output a text file named text.txt.
inside this text file there some reading for example :
2pm henry 25
3pm loew 26
so what i want to do is to called these output in the text file to the table and i want the table to be like html table which has column and rows...anyways thanks for ur information..hehe
Old 10-27-2011, 10:13 AM   #6
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,397
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
I think you need to define what constitutes a table. Programmatically, your existing text data constitutes a table, since it is easily parsed as rows and columns, where rows are delimited by newlines, and fields/columns are delimited by whitespace. A spreadsheet program would probably import such data into cells in row/column format exactly as you would expect.
If you just want the columns to have some distinct visual alignment, then use whitespace (tabs &/or spaces) to pad the space between fields. In C, this is easily accomplished with printf() formatting. Consult your local man page for the details on that.
HTML tables will only render as tables when viewed with a browser, so you should consider whether this is appropriate for your application.

--- rod.

Last edited by theNbomr; 10-27-2011 at 10:15 AM.


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
Just curious... r.71 Slackware 16 10-09-2009 04:08 PM
just curious....... peonuser Linux - Software 15 06-09-2009 11:19 PM
just curious mbvo Slackware 15 03-11-2009 08:44 AM
Very curious chbin Linux - Security 13 08-08-2005 10:42 PM
just curious Derek-kun Linux - Newbie 1 09-04-2003 09:53 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:43 PM.

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