473,698 Members | 2,153 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 1756
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
7975
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
2167
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
1922
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
2269
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
2289
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
4758
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
2398
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
1812
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
8603
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
9026
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...
1
8893
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8861
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...
0
7723
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6518
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
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3045
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

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.