468,133 Members | 1,187 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,133 developers. It's quick & easy.

text-formatting program problem...

Any one know how to do this? thank
Write a simple text-formatting program that produces neatly printed
output from input text containing embedded command lines that
determine how to format the output; all lines begin with a period are
command lines. The task of the program is to collect words from input
lines, fill output lines with those words, adjust the margins, and
print the result. Your programs should handle the commands shown in
Table 1 and should make use of functions.
Table 1 Text formatting commands for Lab #2
Command

..ce n
..ce
..in n
..in n
..in
..po n
..po n
..po
..ll n
..ll
..ls n
..ls
..sp n
..sp
..ad
..na
Description

Centre the next n lines (n might be 0)
Centre the next line
Increase (decrease) the indentation by n spaces
Set the indentation to n spaces
Reset indentation to default (0 spaces)
Increase (decrease) the left margin (page offset) by n spaces
Set the left margin (page offset) to n spaces
Reset margin to default (10 spaces)
Set line length to n spaces
Reset line length to default (100 spaces)
Set interline spacing to n (n = 2 gives double spacing)
Reset to single spacing
Put (n * CurrentLineSpacing) blank lines in the output
Put (1 * CurrentLineSpacing) blank lines in the output
Start adjustment of right margin (default; works in fill mode only)
Stop adjustment of right margin
When the program is filling output lines with input words, it is said
to be operating in fill mode. When not operating in fill mode, lines
should be printed exactly as they appear in the input. When operating
in fill mode, the program also may have to pad each output line evenly
with blank characters to produce a straight right margin; the program
is said to be operating in adjust mode when operating in this manner.
When not in adjust mode, the program will fill output lines but the
right margin will be jagged.

Your program should begin execution using the following default
values: line length is 100 characters, line spacing is 1 (single
spacing), margin is 10 characters, indentation level is 0 characters.
The program begins execution in fill mode, adjusting the right margin.
These defaults should remain in effect until changed by the
appropriate commands. A period, question mark, or exclamation point
should be followed by 2 blank spaces in the output, unless it is at
the end of an output line. A new paragraph should be separated from
the previous by an extra CurrentLineSpacing lines.
Nov 14 '05 #1
6 2348

"shoo" <yu******@gmail.com> wrote in message
news:1a**************************@posting.google.c om...
Any one know how to do this?
Yes.
thank


You're welcome.

[snip homework assignment, accompanied by no
evidence of any attempt]

-Mike
Nov 14 '05 #2
shoo <yu******@gmail.com> scribbled the following:
Any one know how to do this? thank


(Snip homework assignment copied more-or-less verbatim)

We don't do other people's homework for them. Please try it yourself at
first, and if you get stuck, show your code and explain what you are
having problems first. You can also ask your professor for help.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"Bad things only happen to scoundrels."
- Moominmamma
Nov 14 '05 #3
On 12 Feb 2005 21:58:08 -0800, shoo
<yu******@gmail.com> wrote:
Any one know how to do this? thank
Yes, I've written three (one in CORAL-66, one in DEC Fortran-77, one in
C++). And various people wrote runoff, roff, nroff, troff, groff and
others...

I've rewritten parts from scratch, a version in C is used for formatting
help text in xcpp (http://www.keristor.co.uk/stuff/xcpp-0.5.6.tar.gz),
it took me about 30 minutes (it isn't quite as complete, and it doesn't
use the .xx format, but the principle is the same).
Write a simple text-formatting program that produces neatly printed
output from input text containing embedded command lines that
determine how to format the output; all lines begin with a period are
command lines. The task of the program is to collect words from input
lines, fill output lines with those words, adjust the margins, and
print the result. Your programs should handle the commands shown in
Table 1 and should make use of functions.
You could get the code of groff, it's GPL.
Table 1 Text formatting commands for Lab #2


Sounds like homework/coursework to me.

Chris C
Nov 14 '05 #4
shoo wrote:

Any one know how to do this? thank
Yes. After you do the exercise you will too.

Write a simple text-formatting program that produces neatly printed
output from input text containing embedded command lines that
determine how to format the output; all lines begin with a period are
command lines. The task of the program is to collect words from input
lines, fill output lines with those words, adjust the margins, and
print the result. Your programs should handle the commands shown in
Table 1 and should make use of functions.

Table 1 Text formatting commands for Lab #2
Command

.ce n
.ce
.in n
.in n
.in
.po n
.po n
.po
.ll n
.ll
.ls n
.ls
.sp n
.sp
.ad
.na
Description

Centre the next n lines (n might be 0)
Centre the next line
Increase (decrease) the indentation by n spaces
Set the indentation to n spaces
Reset indentation to default (0 spaces)
Increase (decrease) the left margin (page offset) by n spaces
Set the left margin (page offset) to n spaces
Reset margin to default (10 spaces)
Set line length to n spaces
Reset line length to default (100 spaces)
Set interline spacing to n (n = 2 gives double spacing)
Reset to single spacing
Put (n * CurrentLineSpacing) blank lines in the output
Put (1 * CurrentLineSpacing) blank lines in the output
Start adjustment of right margin (default; works in fill mode only)
Stop adjustment of right margin

When the program is filling output lines with input words, it is said
to be operating in fill mode. When not operating in fill mode, lines
should be printed exactly as they appear in the input. When operating
in fill mode, the program also may have to pad each output line evenly
with blank characters to produce a straight right margin; the program
is said to be operating in adjust mode when operating in this manner.
When not in adjust mode, the program will fill output lines but the
right margin will be jagged.

Your program should begin execution using the following default
values: line length is 100 characters, line spacing is 1 (single
spacing), margin is 10 characters, indentation level is 0 characters.
The program begins execution in fill mode, adjusting the right margin.
These defaults should remain in effect until changed by the
appropriate commands. A period, question mark, or exclamation point
should be followed by 2 blank spaces in the output, unless it is at
the end of an output line. A new paragraph should be separated from
the previous by an extra CurrentLineSpacing lines.


--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
Nov 14 '05 #5
Va negvpyr <1n**************************@cbfgvat.tbbtyr.pbz >,
lh******@tznvy.pbz fnlf...
Nal bar xabj ubj gb qb guvf? gunax
Lrf, ohg gur fbyhgvba vf n pnershyyl thneqrq vaqhfgel frperg.
V pbhyq fubj lbh, ohg gura V'q unir gb znxr lbh jngpu ernyvgl
GI.
Jevgr n fvzcyr grkg-sbeznggvat cebtenz gung cebqhprf arngyl cevagrq
bhgchg sebz vachg grkg pbagnvavat rzorqqrq pbzznaq yvarf gung
qrgrezvar ubj gb sbezng gur bhgchg; nyy yvarf ortva jvgu n crevbq ner
pbzznaq yvarf. Gur gnfx bs gur cebtenz vf gb pbyyrpg jbeqf sebz vachg
yvarf, svyy bhgchg yvarf jvgu gubfr jbeqf, nqwhfg gur znetvaf, naq
cevag gur erfhyg. Lbhe cebtenzf fubhyq unaqyr gur pbzznaqf fubja va
Gnoyr 1 naq fubhyq znxr hfr bs shapgvbaf.
Gnoyr 1 Grkg sbeznggvat pbzznaqf sbe Yno #2
Pbzznaq

.pr a
.pr
.va a
.va a
.va
.cb a
.cb a
.cb
.yy a
.yy
.yf a
.yf
.fc a
.fc
.nq
.an
Qrfpevcgvba

Prager gur arkg a yvarf (a zvtug or 0)
Prager gur arkg yvar
Vapernfr (qrpernfr) gur vaqragngvba ol a fcnprf
Frg gur vaqragngvba gb a fcnprf
Erfrg vaqragngvba gb qrsnhyg (0 fcnprf)
Vapernfr (qrpernfr) gur yrsg znetva (cntr bssfrg) ol a fcnprf
Frg gur yrsg znetva (cntr bssfrg) gb a fcnprf
Erfrg znetva gb qrsnhyg (10 fcnprf)
Frg yvar yratgu gb a fcnprf
Erfrg yvar yratgu gb qrsnhyg (100 fcnprf)
Frg vagreyvar fcnpvat gb a (a = 2 tvirf qbhoyr fcnpvat)
Erfrg gb fvatyr fcnpvat
Chg (a * PheeragYvarFcnpvat) oynax yvarf va gur bhgchg
Chg (1 * PheeragYvarFcnpvat) oynax yvarf va gur bhgchg
Fgneg nqwhfgzrag bs evtug znetva (qrsnhyg; jbexf va svyy zbqr bayl)
Fgbc nqwhfgzrag bs evtug znetva
Jura gur cebtenz vf svyyvat bhgchg yvarf jvgu vachg jbeqf, vg vf fnvq
gb or bcrengvat va svyy zbqr. Jura abg bcrengvat va svyy zbqr, yvarf
fubhyq or cevagrq rknpgyl nf gurl nccrne va gur vachg. Jura bcrengvat
va svyy zbqr, gur cebtenz nyfb znl unir gb cnq rnpu bhgchg yvar rirayl
jvgu oynax punenpgref gb cebqhpr n fgenvtug evtug znetva; gur cebtenz
vf fnvq gb or bcrengvat va nqwhfg zbqr jura bcrengvat va guvf znaare.
Jura abg va nqwhfg zbqr, gur cebtenz jvyy svyy bhgchg yvarf ohg gur
evtug znetva jvyy or wnttrq.

Lbhe cebtenz fubhyq ortva rkrphgvba hfvat gur sbyybjvat qrsnhyg
inyhrf: yvar yratgu vf 100 punenpgref, yvar fcnpvat vf 1 (fvatyr
fcnpvat), znetva vf 10 punenpgref, vaqragngvba yriry vf 0 punenpgref.
Gur cebtenz ortvaf rkrphgvba va svyy zbqr, nqwhfgvat gur evtug znetva.
Gurfr qrsnhygf fubhyq erznva va rssrpg hagvy punatrq ol gur
nccebcevngr pbzznaqf. N crevbq, dhrfgvba znex, be rkpynzngvba cbvag
fubhyq or sbyybjrq ol 2 oynax fcnprf va gur bhgchg, hayrff vg vf ng
gur raq bs na bhgchg yvar. N arj cnentencu fubhyq or frcnengrq sebz
gur cerivbhf ol na rkgen PheeragYvarFcnpvat yvarf.


--
Enaql Ubjneq (2ercyl erzbir SBBONE)
"Znxvat vg uneq gb qb fghcvq guvatf bsgra znxrf vg uneq
gb qb fzneg barf gbb." -- Naqerj Xbravt
Nov 14 '05 #6
shoo wrote:
Any one know how to do this? thank


Your first step should be to decide whether to
write this in C or C++. You have posted to
both news:comp.lang.c and news:comp.lang.c++.
These are two different newsgroups and languages.

Please see my reply to your posting in
news:comp.lang.c++.

If you decide to post to more than one newsgroup,
please supply them all on the "To:" field, as
I have done. This will allow others to see
the conversation as a whole. It will allow
you to only need to access one newsgroup,
not both, especially when replying.
--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library

Nov 14 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Jiri Palecek | last post: by
6 posts views Thread by Lance Geeck | last post: by
3 posts views Thread by jweinberg1975 | last post: by
3 posts views Thread by bbepristis | last post: by
10 posts views Thread by bluemountain | last post: by
2 posts views Thread by dpw.asdf | last post: by
27 posts views Thread by didacticone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.