473,670 Members | 2,397 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

K&R2 Ex 5-11 : What is it asking for?

Hi,
My english is not top notch and I am trying to understand what K&R2 Ex
5-11 is asking for (pg 118).

It says: Modify the programs entab and detab (which I completed from
chapter 1 and have on hand) to accept a list of tab stops as arguments.
Use the default tab settings if there are no arguments.

I am having difficulty understanding the question (not asking for
answer to it). Any help would be helpful (thus the common root "help").

Nov 14 '05 #1
6 1752
Deniz Bahar <de*********@gm ail.com> wrote:
My english is not top notch and I am trying to understand what K&R2 Ex
5-11 is asking for (pg 118). It says: Modify the programs entab and detab (which I completed from
chapter 1 and have on hand) to accept a list of tab stops as arguments.
Use the default tab settings if there are no arguments. I am having difficulty understanding the question (not asking for
answer to it). Any help would be helpful (thus the common root "help").
As far as I can tell it means to change the program so that tab
stops (i.e. the places where the cursor ends up when you press
the tab key) aren't always e.g. 4 spaces appart (so that tab
stops are at positions 4, 8, 12, ...) but that you can tell it
that tab stops are e.g. at arbitrary position like 5, 7, 14, 23,
etc. So, when you call the modified program like this
detab 5 7 14 23 25 27 33 39 42


it puts in as many space characters that you end up in column 5 after
the first tab character, in column 7 after the second, in column 14
after the third etc.

If you ever get hold of a mechanical typewriter you will find that
it also has a tab key, but that you have to set "tab stops" at the
positions you want it to stop (it has an extra key for setting and
unsetting them). That was used e.g. for filling in forms and proba-
bly is what tabs where invented for in the first place.

Regards, Jens
--
\ Jens Thoms Toerring ___ Je***********@p hysik.fu-berlin.de
\______________ ____________ http://www.toerring.de
Nov 14 '05 #2
Deniz Bahar wrote:

My english is not top notch and I am trying to understand what K&R2
Ex 5-11 is asking for (pg 118).

It says: Modify the programs entab and detab (which I completed
from chapter 1 and have on hand) to accept a list of tab stops as
arguments. Use the default tab settings if there are no arguments.

I am having difficulty understanding the question (not asking for
answer to it). Any help would be helpful (thus the common root
"help").


Here is the help screen from my own version, which I have been
using for a while. Maybe it will clarify what is wanted.

[1] c:\c\hshftst>de tab
DETAB copyright (c) 1989 by C.B. Falconer. Ver 1.0

usage: DETAB [tablist] <infile >outfile
If tablist is omitted a tab interval of 8 is assumed
If tablist has only one number, then that is the tab interval
If tablist contains multiple numbers, separated by spaces,
then they are assumed to be the tab points. The leftmost
column is numbered 0.
If tablist is a single 0, then tabs are not expanded
Backspaces in a line shut off tab expansion until cr

Any isolated lf's are converted into cr/lf pairs (Unix files)
Omitting the "<infile" causes this help screen

--
Chuck F (cb********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!

Nov 14 '05 #3
CBFalconer wrote:
Deniz Bahar wrote:

My english is not top notch and I am trying to understand what K&R2
Ex 5-11 is asking for (pg 118).

It says: Modify the programs entab and detab (which I completed
from chapter 1 and have on hand) to accept a list of tab stops as
arguments. Use the default tab settings if there are no arguments.

I am having difficulty understanding the question (not asking for
answer to it). Any help would be helpful (thus the common root
"help").
Here is the help screen from my own version, which I have been
using for a while. Maybe it will clarify what is wanted.

[1] c:\c\hshftst>de tab
DETAB copyright (c) 1989 by C.B. Falconer. Ver 1.0

usage: DETAB [tablist] <infile >outfile
If tablist is omitted a tab interval of 8 is assumed


Is this an unspoken standard?

If tablist has only one number, then that is the tab interval

If tablist contains multiple numbers, separated by spaces,
then they are assumed to be the tab points. The leftmost
column is numbered 0.
Do programs like notepad, vi also consider the first column 0, instead
of 1?

How many arguments do you expect the user to enter in this mode? What
if he/she only give 2 arguments, but a line of inputs has > 2 tabs? Do
you ignore the rest of the tabs?

Also, do you limit the maximum size of a tabpoint to 80 or some other
value?
If tablist is a single 0, then tabs are not expanded
Backspaces in a line shut off tab expansion until cr
How do you detect backspaces? Aren't backspaces taken care of by
hardware/tty drivers or some other layer of the OS?

Any isolated lf's are converted into cr/lf pairs (Unix files)
Omitting the "<infile" causes this help screen

Isn't a UNIX text file ending with LF and Windows CRLF?

--
Chuck F (cb********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!


Thank you for your help.

Nov 14 '05 #4
Je***********@p hysik.fu-berlin.de wrote:
Deniz Bahar <de*********@gm ail.com> wrote:
My english is not top notch and I am trying to understand what K&R2 Ex 5-11 is asking for (pg 118).
It says: Modify the programs entab and detab (which I completed from chapter 1 and have on hand) to accept a list of tab stops as arguments. Use the default tab settings if there are no arguments.

I am having difficulty understanding the question (not asking for
answer to it). Any help would be helpful (thus the common root

"help").
As far as I can tell it means to change the program so that tab
stops (i.e. the places where the cursor ends up when you press
the tab key) aren't always e.g. 4 spaces appart (so that tab
stops are at positions 4, 8, 12, ...) but that you can tell it
that tab stops are e.g. at arbitrary position like 5, 7, 14, 23,
etc. So, when you call the modified program like this
detab 5 7 14 23 25 27 33 39 42
it puts in as many space characters that you end up in column 5 after
the first tab character, in column 7 after the second, in column 14
after the third etc.


Thank you for clearing that up. Do you think there should be a limit
on the number of tabpositions given by the user, or the size of the
positions? What if the user gives me 3 positions, but some of his/her
lines has >3 tabs? I am really not sure how to organize the parameters
for input and operation. What type of error checking do you think is
valid here? Posibble checking the each number is larger than the
previous, and is not less than 1 or greater than some max value (like
80)?

If you ever get hold of a mechanical typewriter you will find that
it also has a tab key, but that you have to set "tab stops" at the
positions you want it to stop (it has an extra key for setting and
unsetting them). That was used e.g. for filling in forms and proba-
bly is what tabs where invented for in the first place.

Last time I saw a mechanical typewriter, I was too young to even know
what the thing was :-) But I get what you're saying, there are
physical stops in these machines, much like the software stops that
programs like vi/notepad have for the TAB character.

Regards, Jens
--
\ Jens Thoms Toerring ___ Je***********@p hysik.fu-berlin.de
\______________ ____________ http://www.toerring.de


Thank you for your help

Nov 14 '05 #5
Deniz Bahar wrote:
CBFalconer wrote:
Deniz Bahar wrote:
My english is not top notch and I am trying to understand what K&R2
Ex 5-11 is asking for (pg 118).

It says: Modify the programs entab and detab (which I completed
from chapter 1 and have on hand) to accept a list of tab stops as
arguments. Use the default tab settings if there are no arguments.

I am having difficulty understanding the question (not asking for
answer to it). Any help would be helpful (thus the common root
"help").
Here is the help screen from my own version, which I have been
using for a while. Maybe it will clarify what is wanted.

[1] c:\c\hshftst>de tab
DETAB copyright (c) 1989 by C.B. Falconer. Ver 1.0

usage: DETAB [tablist] <infile >outfile
If tablist is omitted a tab interval of 8 is assumed


Is this an unspoken standard?


<OT>
AFAIK, yes. I could not turn up anything official on this.
However, for many editors, the standard tabstops are at 8.
</OT>
If tablist has only one number, then that is the tab interval

If tablist contains multiple numbers, separated by spaces,
then they are assumed to be the tab points. The leftmost
column is numbered 0.


Do programs like notepad, vi also consider the first column 0, instead
of 1?


<OT>
Usually, editors see the position before the first character as
column 0 and after the first character as column 1.
</OT>

How many arguments do you expect the user to enter in this mode? What
if he/she only give 2 arguments, but a line of inputs has > 2 tabs? Do
you ignore the rest of the tabs?

Also, do you limit the maximum size of a tabpoint to 80 or some other
value?

If tablist is a single 0, then tabs are not expanded
Backspaces in a line shut off tab expansion until cr


How do you detect backspaces? Aren't backspaces taken care of by
hardware/tty drivers or some other layer of the OS?


'\b' is the backspace character. How you get this character
into the input, is your problem and may be not possible on
stdin for your implementation (redirected input from a file
should do, however; if you need a '\b' in your file, there
are always the C file output functions...).
Any isolated lf's are converted into cr/lf pairs (Unix files)
Omitting the "<infile" causes this help screen


Isn't a UNIX text file ending with LF and Windows CRLF?


If you mean "newline is encoded as ...": yep.
The help is ambiguous here; I understand "(Unix files)"
as "this happens for Unix files". This is only an issue if you
consider files with different encodings which also means that you
have to access the files in binary mode.
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Nov 14 '05 #6
Deniz Bahar <de*********@gm ail.com> wrote:
Je***********@p hysik.fu-berlin.de wrote:
Deniz Bahar <de*********@gm ail.com> wrote:
> My english is not top notch and I am trying to understand what K&R2 Ex > 5-11 is asking for (pg 118).

> It says: Modify the programs entab and detab (which I completed from > chapter 1 and have on hand) to accept a list of tab stops as arguments. > Use the default tab settings if there are no arguments.

> I am having difficulty understanding the question (not asking for
> answer to it). Any help would be helpful (thus the common root

"help").

As far as I can tell it means to change the program so that tab
stops (i.e. the places where the cursor ends up when you press
the tab key) aren't always e.g. 4 spaces appart (so that tab
stops are at positions 4, 8, 12, ...) but that you can tell it
that tab stops are e.g. at arbitrary position like 5, 7, 14, 23,
etc. So, when you call the modified program like this
> detab 5 7 14 23 25 27 33 39 42


it puts in as many space characters that you end up in column 5 after
the first tab character, in column 7 after the second, in column 14
after the third etc.


Thank you for clearing that up. Do you think there should be a limit
on the number of tabpositions given by the user, or the size of the
positions? What if the user gives me 3 positions, but some of his/her
lines has >3 tabs? I am really not sure how to organize the parameters
for input and operation. What type of error checking do you think is
valid here? Posibble checking the each number is larger than the
previous, and is not less than 1 or greater than some max value (like
80)?


Difficult to say since K&R doesn't say. Putting in unnecessary limits
(like a maximum number of tab positions) doesn't sound like a very
good idea to me. About the rest you probably will have to figure out
something that seems to be reasonable (like if there are more tab
characters in a line than the user supplied tab positions reverting to
a default of e.g. tab stops at multiples of 8). Checking that the
tab stop positions the user defines are increasing sounds reasonable,
but you could also assume that too small a value is meant as an in-
crement instead of an absolute position. Of course, all values need
to be larger than 0. If you want a restriction of 80 chars max as tab
stop positions it's up to you, but I wouldn't know why you would want
to do that.
Regards, Jens
--
\ Jens Thoms Toerring ___ Je***********@p hysik.fu-berlin.de
\______________ ____________ http://www.toerring.de
Nov 14 '05 #7

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

Similar topics

5
7972
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!
12
2165
by: Chris Readle | last post by:
Ok, I've just recently finished a beginning C class and now I'm working through K&R2 (alongside the C99 standard) to *really* learn C. So anyway, I'm working on an exercise in chapter one which give me strange behavior. Here is the code I've written: /****************************************************************************** * K&R2 Exercise 1-9 * Write a program to copy its input to its output, replacing strings of blanks * with a...
16
1676
by: TTroy | last post by:
I FOUND MAJOR ERRORS in K&R2 (making it almost useless for the herein mentioned topics). K&R2 Section 5.9 Pointers vs. Multidimension Arrays starts of like this... "Newcomers to C are somtimes confused about the difference between a two-dimensional array and an array of pointers..." then continues to explain int *b; to be...
3
1920
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 the one by Dennis Ritchie is good but can any one mention some other books as well Thanx.
16
2268
by: Josh Zenker | last post by:
This is my attempt at exercise 1-10 in K&R2. The code looks sloppy to me. Is there a more elegant way to do this? #include <stdio.h> /* copies input to output, printing */ /* series of blanks as a single one */ int main() { int c;
2
2288
by: arnuld | last post by:
there is a solution on "clc-wiki" for exercise 1.17 of K&R2: http://clc-wiki.net/wiki/K%26R2_solutions:Chapter_1:Exercise_17 i see this uses pointers whereas K&R2 have not discussed pointers yet. i have created a solution myself by modifying the example programme of section 1.19. i tried to find the source-code of K&R2 using Google. i found the home
8
4754
by: arnuld | last post by:
i have created a solutions myself. it compiles without any trouble and runs but it prints some strange characters. i am not able to find where is the trouble. --------------------------------- PROGRAMME -------------------------------- /* K&R2 section 1.9 exercise 1.19
19
2396
by: arnuld | last post by:
this programme runs without any error but it does not do what i want it to do: ------------- PROGRAMME -------------- /* K&R2, section 1.6 Arrays; Exercise 1-13. STATEMENT: Write a program to print a histogram of the lengths of words in its input. It is easy to draw the histogram with the bars horizontal; a vertical
24
1798
by: Anthony Irwin | last post by:
Hi all, I have been going through the k&r2 book and all the examples are done with main() instead of int main(void) and k&r2 in the start of chapter 1 does not return 0 so I haven't yet either. I did two compiles shown below. $ gcc -std=c89 -Wall exercise_1-9.c -o exercise_1-9 exercise_1-9.c:5: warning: return type defaults to `int'
15
1808
by: arnuld | last post by:
STATEMENT: Write the function strindex(s, t), which returns the position of the rightmost occurence of t in s, or -1 if there is none. PURPOSE: this program prints the index of the rightmost match on the line. The match we have to find is a char array named pattern. We also print out the number of matches we have found. We will take the input from command-line. PROBLEM: Segmentation Fault
0
8469
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8386
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8903
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8814
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8661
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6213
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4211
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2800
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2042
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.