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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started