473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

What does Kernighan and Ritchie mean by 'trailing'?

This isn't entirely related to C, but Kernighan and Ritchie asks in
Execise 1-18 of their C programming language book to 'Write a program
to remove trailing blanks and tabs from each line of input, and to
delete entirely blank lines'. What do they mean by trailing?

Dec 30 '05 #1
4 4354

Albert wrote:
This isn't entirely related to C, but Kernighan and Ritchie asks in
Execise 1-18 of their C programming language book to 'Write a program
to remove trailing blanks and tabs from each line of input, and to
delete entirely blank lines'. What do they mean by trailing?


It means they trail the non-blank text.

"what hath god wrought"

has no trailing blanks, although it does have 3 internal blanks.

"watson, come here I need you "

has 4 trailng blanks after "you", the other block of 4 contiguous
blanks are still internal. If you do the excercise correctly, you'll
get

"watson, come here I need you"

You'll often find this implemented as a TRIM function which usually
removes contiguous spaces from the start of a line also.

Dec 30 '05 #2

Albert wrote:
This isn't entirely related to C, but Kernighan and Ritchie asks in
Execise 1-18 of their C programming language book to 'Write a program
to remove trailing blanks and tabs from each line of input, and to
delete entirely blank lines'. What do they mean by trailing?


It means 'following'.

Let's consider <T> as a placeholder for a tab and <S> for a space. If
you have the line:

This<S>is<S>a<S><T>test.<S><S><T><S>

Then the trailing spaces are the ones following the last printable
character excluding the <S> and <T> characters themselves, i.e.
<S><S><T><S> so your result would be:

This<S>is<S>a<S><T>test.

If you have a line like:

<S><T><S><S>

then all those characters should be removed and you're left with an
empty string.

I think this is called trimming. Some languages offer 3 functions:
rtrim, ltrim and trim. rtrim trims the right (trailing) side of a
string, ltrim trims the left (leading) side and trim both sides. Python
has all three functions, although they're called rstrip, lstrip and
strip and don't necessarily work only for spaces and tabs. I don't
think C has any functions like that, although it should be easy to
write down something simple. I guess that's what you have to do :-)

Dec 30 '05 #3
On 29 Dec 2005 18:56:08 -0800, in comp.lang.c , "Albert"
<al*****************@gmail.com> wrote:
This isn't entirely related to C, but Kernighan and Ritchie asks in
Execise 1-18 of their C programming language book to 'Write a program
to remove trailing blanks and tabs from each line of input, and to
delete entirely blank lines'. What do they mean by trailing?


Trailing: lagging behind, coming after.
Mark McIntyre
--

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Dec 30 '05 #4

"Albert" <al*****************@gmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
This isn't entirely related to C, but Kernighan and Ritchie asks in
Execise 1-18 of their C programming language book to 'Write a program
to remove trailing blanks and tabs from each line of input, and to
delete entirely blank lines'. What do they mean by trailing?


const char *line1 = "This line contains two trailing blanks and one"
" trailing tab character \t \n";

const char *line2 = "This line contains no trailing spaces or
" tab characters\n";
const char *line3 = "\n"; /* this line is empty */
-Mike
Dec 30 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: David | last post by:
this phrase has been mentioned many times in this NG and it seems like everyone know what it's. is it a book? a standard? or a guide of some sort? where can i read more about K&R2? thanks!
6
by: erebus- | last post by:
When learning the C programing languages, i have had and still am having the problem of not being able to find answers to many questions. Is their an overall guide/reference that someone knows?
4
by: Luke Wu | last post by:
I am just wondering what the following terms usually mean: 1) "Standard C" 2) "K&R C" 3) "ANSI C" I am pretty sure "ANSI C" usually refers to the C89 standard, but what
9
by: niclane | last post by:
Hi, I was reading section 5.5 of Ritchie and Kernighan and saw the following: " ..... char amessage = "now is the time"; char *pmessage = "now is the time";
35
by: wilsonidv | last post by:
Daer All: I have studied C language for just 2~3 months. I'd like to know the critical parts of C, focusing on these. Could anyone has many experiences tell me, please. Thanks and Regards.
3
by: Sunny | last post by:
Hi, Well this might look like a dumb question to 99.99% of u but what exactly is K&R2 and where can I get it? Secondly alot of people say that you can learn by reading good books on C. I know...
37
by: Erick-> | last post by:
hello!! I was looking at some code in C... and saw this "exotic" operator |=. first time with it, what exactky does??? thanks in advance. Erick->
9
by: Cao Yi | last post by:
Hi, here's a fract of codes, and what's the line "scanf("%lf%*", &cvi)" doing? ============================= do { printf("\nCoefficient: "); scanf("%lf%*", &cvi); getchar(); } while (cvi <=...
13
by: anotherlin | last post by:
Hi everyone, I've read the Kernighan and Ritchie some time ago, and then again, but this time I've done the full set of exercises. I figured it would be nice to share them : ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.