473,696 Members | 1,935 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

I don't quite understand this exercise...

I don't quite understand what K&R want me to do in Exercise 1-20 in "The
C Programming Language, 2nd Edition". Here's the description:

"Write a program detab that replaces tabs in the input with the proper
number of blanks to space to the next tab stop. Assume a fixed set of
tab stops, say every n columns. Should n be a variable or a symbolic
parameter?"

What does this mean? Do they want me to figure out the amount of spaces
a tab takes up on my system, and add them? I'm sort of confused about
this question.

--
Patrick M.
/* EOF */
Nov 15 '05 #1
10 3464
"Patrick M." <no***@nowhere. com> wrote in message
news:bZ******** ************@co mcast.com...
I don't quite understand what K&R want me to do in Exercise 1-20 in "The
C Programming Language, 2nd Edition". Here's the description:

"Write a program detab that replaces tabs in the input with the proper
number of blanks to space to the next tab stop. Assume a fixed set of
tab stops, say every n columns. Should n be a variable or a symbolic
parameter?"

What does this mean? Do they want me to figure out the amount of spaces
a tab takes up on my system, and add them? I'm sort of confused about
this question.


You can assume a fixed pitch font, but should you assume a fixed tab size ?

--
Chqrlie.
Nov 15 '05 #2
>"Write a program detab that replaces tabs in the input with the proper
number of blanks to space to the next tab stop. Assume a fixed set of
tab stops, say every n columns. Should n be a variable or a symbolic
parameter?"

What does this mean? Do they want me to figure out the amount of spaces
a tab takes up on my system, and add them? I'm sort of confused about
this question.


Let me ask a question I think is related: should you have to
recompile the program to change from assuming tab stops every 4
columns to every 8 columns, or should this be a command-line
parameter?

Gordon L. Burditt
Nov 15 '05 #3
Patrick M. wrote:
I don't quite understand what K&R want me to do in Exercise 1-20 in "The
C Programming Language, 2nd Edition". Here's the description:

"Write a program detab that replaces tabs in the input with the proper
number of blanks to space to the next tab stop. Assume a fixed set of
tab stops, say every n columns. Should n be a variable or a symbolic
parameter?"

What does this mean? Do they want me to figure out the amount of spaces
a tab takes up on my system, and add them? I'm sort of confused about
this question.


They mean: write a program to read a text file (or stdin) with tabs and
replace all the tabs with equivalent space characters. The result
should be an output file (or stdout). This is a general type of program
known as a filter, which takes one input file and produces an associated
output file with some defined modification.

They are suggesting that you might want to allow some way to specify the
tab spacing or tab columns that your input file assumes. That can be
done with a command line parameter.

Thad

Nov 15 '05 #4
Gordon Burditt wrote:
"Write a program detab that replaces tabs in the input with the proper
number of blanks to space to the next tab stop. Assume a fixed set of
tab stops, say every n columns. Should n be a variable or a symbolic
parameter?"

What does this mean? Do they want me to figure out the amount of spaces
a tab takes up on my system, and add them? I'm sort of confused about
this question.

Let me ask a question I think is related: should you have to
recompile the program to change from assuming tab stops every 4
columns to every 8 columns, or should this be a command-line
parameter?


Just to add one thing the OP may have missed (although I'll own
up now to never having read K&R): tabs are typically used to
indicate that the next character goes at the start of the
'next'[1] 'tab column' i.e. they have variable width.

[1] Inverted quotes because they typically leave a space, so the
start of the 'next' column is not always the immediately
following column.
|
---> (think of the above as an example of resulting layout)

--
imalone
Nov 15 '05 #5
Thad Smith wrote:
Patrick M. wrote:
I don't quite understand what K&R want me to do in Exercise 1-20 in
"The C Programming Language, 2nd Edition". Here's the description:

"Write a program detab that replaces tabs in the input with the proper
number of blanks to space to the next tab stop. Assume a fixed set of
tab stops, say every n columns. Should n be a variable or a symbolic
parameter?"

What does this mean? Do they want me to figure out the amount of
spaces a tab takes up on my system, and add them? I'm sort of confused
about this question.


They mean: write a program to read a text file (or stdin) with tabs and
replace all the tabs with equivalent space characters. The result
should be an output file (or stdout). This is a general type of program
known as a filter, which takes one input file and produces an associated
output file with some defined modification.

They are suggesting that you might want to allow some way to specify the
tab spacing or tab columns that your input file assumes. That can be
done with a command line parameter.

Thad


Ok, thanks, and everyone else. So what you're saying is, they want me to
ask the user/get and set a variable, say n, and replace all tabs with n
spaces, and they don't want me to calculate the number of spaces a tab
takes up on the system?

Thanks for all the replies.

--
Patrick M.
/* EOF */
Nov 15 '05 #6
>Ok, thanks, and everyone else. So what you're saying is, they want me to
ask the user/get and set a variable, say n, and replace all tabs with n
spaces, and they don't want me to calculate the number of spaces a tab
takes up on the system?


How can you possibly calculate the number of spaces a tab takes up
on the system? (Isn't this a little like calculating the color of
the nail polish on THE thumb of THE human?) It could be that there
are many different terminals and printers, all with different tab
stop settings, and in any case, there's no portable way to read the
location of the cursor after sending a tab.

There are some conventions where a file is labelled with the number
of spaces a tab should take up while editing it with vi, but that's
hardly universal (and using it tends to be a security hole). I've
seen only a very few files actually using such labelling. Some
files have comments like "view me with 4 space tabs". It is often
the case that even the files in the same directory are not consistent
among themselves.

Gordon L. Burditt
Nov 15 '05 #7
Gordon Burditt wrote:
Ok, thanks, and everyone else. So what you're saying is, they want me to
ask the user/get and set a variable, say n, and replace all tabs with n
spaces, and they don't want me to calculate the number of spaces a tab
takes up on the system?


How can you possibly calculate the number of spaces a tab takes up
on the system? (Isn't this a little like calculating the color of
the nail polish on THE thumb of THE human?) It could be that there
are many different terminals and printers, all with different tab
stop settings, and in any case, there's no portable way to read the
location of the cursor after sending a tab.

There are some conventions where a file is labelled with the number
of spaces a tab should take up while editing it with vi, but that's
hardly universal (and using it tends to be a security hole). I've
seen only a very few files actually using such labelling. Some
files have comments like "view me with 4 space tabs". It is often
the case that even the files in the same directory are not consistent
among themselves.

Gordon L. Burditt


Yes, you do have a point there... :D But there could possibly be a way,
I just wasn't sure if that's what they wanted me to do; you never know.
Thanks for clearing it up for me.

--
Patrick M.
/* EOF */
Nov 15 '05 #8
"Patrick M." wrote:
Ok, thanks, and everyone else. So what you're saying is, they want me to
ask the user/get and set a variable, say n, and replace all tabs with n
spaces, and they don't want me to calculate the number of spaces a tab
takes up on the system?

Almost there... They are asking for a program that will take as input:

(a) A text file containing some tab characters. And
(b) A number 'N' telling what is the tab "spacing"

And produce, as output, a text file where every tab has been replaced
by a *variable* number of spaces between 1 and N so that the file
"looks" similar to the original when displayed or printed in a device
that uses 'N' colums per tab.

For example, if N is 4 and the original file is:

int i = 0;
int jj = 0;
int kkk = 0;

Containing a tab before each 'int', a space after each 'int' and a tab
before each '=', the output should be:

int i = 0;
int jj = 0;
int kkk = 0;

containing 4 spaces before each int, one space after each int, 3
spaces after 'i', 2 spaces after 'jj' and 1 space after 'kkk';

Roberto Waltman

[ Please reply to the group, ]
[ return address is invalid. ]
Nov 15 '05 #9
On Mon, 26 Sep 2005 19:46:41 -0000, in comp.lang.c ,
go***********@b urditt.org (Gordon Burditt) wrote:
How can you possibly calculate the number of spaces a tab takes up
on the system?


One assumes, dear boy, they mean the system the acolyte is sitting
before, perhaps ?

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-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 =----
Nov 15 '05 #10

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

Similar topics

303
17631
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b. Yahoo store was originally written in Lisp. c. Emacs The issues with these will probably come up, so I might as well mention them myself (which will also make this a more balanced
5
2530
by: Charles | last post by:
I am going through the exercises and Bruce Eckel's Thinking in C++ and I ran into an exercise that wasn't included in his solutions that I think I could use some assistance with. Exercise 3-26 pg 213: Define an array of int. Take the starting address of that array and use static_cast to convert it into an void*. Write a function that takes a void*, a number (indicating a number of bytes), and a value (indicating the value to which...
22
1635
by: Suzie | last post by:
Hi guys, I've been coding in C for several years and I'm getting started with C++. I was given the following exercise to do and I don't quite understand it. I was wondering if any of you guys could help. #include <iostream> using namespace std;
10
1782
by: Simon Mansfield | last post by:
I have been given a list of exercises to do by my tutor, one of which is this: http://www.cems.uwe.ac.uk/~amclymer/Software%20Design%20and%20C++/Exercises/Exercise%208/Exercise.html Which i am finding very difficult to understand what is required and how exactly to do it.. Any thoughts/idea's will be greatfully recieved! Global_Inferno
5
3033
by: ebrimagillen | last post by:
Hello mates, Just needed a solution on the exercises below. Exercise 2 A classic problem in introductory programming is the grains of rice on a chess board problem. Your program should calculate the number of rice grains on the last square of a 64 square chess board given that there is 1 grain of rice on the first square, 2 on the second square, 4 on the third square and so on. Use a while loop to double the number of rice grains and...
8
1413
by: Indian.croesus | last post by:
Hi, I apologise if this is not the forum for my question. I am a starter in C and I have come to a point where I can not figure out if knowledge of assembly language is really essential for an in depth understanding of C. Also while going through some of the old posts, essentially as an exercise to understand C better, I read the following from one Mr. Keith. "One concrete example is the C implementation on Cray vector machines.
17
2716
by: stdazi | last post by:
Hello! Many times I was suggested to use xrange and range instead of the while constructs, and indeed, they are quite more elegant - but, after calculating the overhead (and losen flexibility) when working with range/xrange, and while loops, you get to the conclusion that it isn't really worth using range/xrange loops. I'd like to show some examples and I'll be glad if someone can suggest some other fixes than while a loop :-)
5
2812
by: Richard Gromstein | last post by:
Hello, I have an exercise that I need to finish very soon and I really need help understanding what to do and how exactly to do it. I am working on reading the chapter right now and working on it myself, but I have a feeling I won't get far. Please help me complete the exercise. I am posting what needs to be done and will be updating with pieces of code that I come up with. Thank you all for your attention. ...
0
8667
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
9148
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
9012
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
8880
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
8853
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
7708
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...
0
5857
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
4357
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
3034
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.