Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

4. Program: uniq This program is an exercise with dynamic data structures as a warm-up for Assignment 2. Write a version of the unix utility

4. Program: uniq This program is an exercise with dynamic data structures as a warm-up for Assignment 2. Write a version of the unix utility program uniq(1). This program will act as a filter, removing adjacent duplicate lines as it copies its stdin to its stdout. That is, any line that is identical to the previous line will be discarded rather than copied to stdout. Your program may not impose any limits on file size or line length. To get started, I highly recommend writing a function char *read long line(FILE *file) that will read an arbitrarily long line from the given file into newly-allocated space. Once you have that, the program is easy. Be careful to free memory once you are done with it. A memory leak could be a real problem for a program like this. Note: even a utility as simple as this has decisions that must be made and specifications that must be negotiated. For example, a line that does not end with a newline is considered the same as one that does. From the specification3: Also Note: For this, you may not use getline(3) or equivalent, since the whole point of the exercise is to learn to do dynamic memory management. The uniq utility shall read an input file comparing adjacent lines, and write one copy of each input line on the output. The second and succeeding copies of repeated adjacent input lines shall not be written. The trailing of each line in the input shall be ignored when doing comparisons. Repeated lines in the input shall not be detected if they are not adjacent.image text in transcribed

Program: unlq This program is an exercise with dynamic data structures as a warm-up for Assignment 2. Write a version of the unix utility program uniq(1). This program will act as a filter, removing adjacent duplicate lines as it copies its stdin to its stdout. That is, any line that is identical to the previous line will be discarded rather than copied to stdout. Your program may not impose any limits on file size or line length. To get started, I highly recommend writing a function char *read_long_line(FILE *file) that will read an arbitrarily long line from the given file into newly-allocated space. Once you have that, the program is easy. Be careful to free memory once you are done with it. A memory leak could be a real problem for a program like this. Note: even a utility as simple as this has decisions that must be made and specifications that must be negotiated. For example, a line that does not end with a newline is considered the same as one that does. From the specification 3 : Also Note: For this, you may not use getline(3) or equivalent, since the whole point of the exercise is to learn to do dynamic memory management. "The uniq utility shall read an input file comparing adjacent lines, and write one copy of each input line on the output. The second and succeeding copies of repeated adjacent input lines shall not be written. The trailing of each line in the input shall be ignored when doing comparisons. "Repeated lines in the input shall not be detected if they are not adjacent

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

3rd Edition

978-1119907466

More Books

Students also viewed these Databases questions