Question: 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.4. Program: uniq This program is an exercise with dynamic data structures

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!