Design in c a unix utility program gasp

Assignment Help C/C++ Programming
Reference no: EM1368794

Design in C a Unix utility program gasp. The command

gasp [options] STRING FILE...

should read the listed files (FILE...) and copy each line from the input to stdout if it contains STRING. Each output line should be preceded by the name of the file that contains it. The argument STRING may be any sequence of characters (as expanded, of course, by the shell depending on how it is quoted). There are two available options, which may appear in any order if both are present:

* -i Ignore case when searching for lines that contain STRING. If the -i option is used, the strings "this", "This", "THIS", and "thiS" all match; if -i is not used, they are all considered different.
* -n Number lines in output. Each line copied to stdout should include the line number in the file where it was found in addition to the file name. The lines in each file are numbered from 1.

Your program does not need to be able to handle combinations of option letters written as a single multi-character option like -in or -ni. But it does need to be able to handle any combination of either or both (or neither) option when they appear separately on the command line.

Besides the general specification given above, your program should meet the following requirements.

1. Be able to handle input lines containing up to 500 characters (including the terminating ). This number should not be hard-wired everywhere in the code, but should be specified with an appropriate #define preprocessor command so it can be changed easily. Your program is allowed to produce incorrect results or fail if presented with input data containing lines longer than this limit.

2. You may assume that the string pattern on the command line is no longer than 100 characters (including the terminating ). This length should also be specified by an appropriate #define.

3. Use standard C library functions where possible; do not reimplement operations available in the basic libraries. For instance, strncpy in <string.h> can be used to copy -terminated strings; you should not be writing loops to copy such strings one character at a time.
Exception: there is a getopt function in the Linux library that provides simplified handling of command line options. For this assignment, only, you may not use this function. You should implement the processing of command line options yourself, of course using the string library functions when these are helpful.

4. You should use "safe" versions of file and string handling routines such as fgets and strncpy instead of routines like gets and strcpy. The safe functions allow specification of maximum buffer or array lengths and will not overrun adjacent memory if used properly.

5. For the -i option, two characters are considered to be equal ignoring case if they are the same when translated by the tolower(c) function (or, alternatively, toupper(c)) in <ctype.h>.

6. If an error occurs when opening or reading a file, the program should write an appropriate error message to stderr and continue processing any remaining files on the command line.

Reference no: EM1368794

Questions Cloud

Which job pays the higher salary : The other pays pays $97,000 annually, but your salary will grow at 12%. After ten years, which job pays the higher salary?
Corporate governance - key informaiton : Explain an experience you have had or have knowledge of pertaining to the functioning of a Board in its role of governance and explain the interplay between the Board, the CEO and other stakeholders
Managerial decisions for company : Higher unemployment caused by ression and higher prices have contributed to substantial reduction during 2008 in the number of vehicles on bridges, roads, and in tunnels.
Explain conclusions differ from recommendations : Explain Conclusions differ from recommendations in that conclusions suggest what ought to be done about the facts
Design in c a unix utility program gasp : Design in C a Unix utility program gasp. Command gasp [options] STRING FILE... must read listed files (FILE...) and copy each line from input to stdout if it contains STRING.
How high above the water was : A car travelling at 19 {rm m/s} runs out of gas while travelling up a 21^circ slope. How far would the car go up the hill before it runs out of gas.
Show earned value management and firm fixed price : Show Earned Value Management and Firm Fixed Price also defne what is the Contracting Officer's role in Earned Value Management
Solving population based question : The Bureau of Labor Statistics announced that in February 2008, of all adult Americans, 145, 999,000 was employed, 7,381,000 were unemployed, and 79,436,000 were not in labor force.
Explain the lifecycle and the age to be in that lifecycle : Explain the lifecycle and the age to be in that lifecycle and Describe nutritional challenges associated with that particular lifecycle.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Create class has three pieces of information as data members

Create a class called Date in C++ that includes three pieces of information as data members: month (type int), day (type int) and yaer (type int).

  Write a matrix multiplication program

Write a C++, matrix multiplication program which you can instrument to monitor and measure execution time as a function of problem size. Make sure it works in Microsoft Visual Studio.

  Structured programming using procedural languages

A a program that is called "Playing with Numbers or Letters".

  Program which asks the user for due date of next assignment

Write a program which asks the user for due date of the next assignment (hours, minutes). Then print number of minutes between the current time and the due date in format.

  Write c program that prompts for variable number of integers

Write a C program that prompts for a variable number of integers, adds them up, averages them, and prints out the average.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Write application to calculate price of carpeting for room

The Westfield Carpet Company has asked you to write an application that calculates the price of carpeting for rectangular rooms.

  Write a complete c++ program

The main program will read in a parameter value n (read this in main). Then it will call a function read2arrays (details below) to read lists of grades into two arrays, which the main program will call test1 and test2 (or some other names of your ..

  C program to calculate power loss in transmission line

Write program in C to calculate the power loss in transmission line with resistance of 0.05 ohms/mile. Calculate power loss if 500 kW of power is transmitted from power generation station

  You will create a linked list module

You will create a linked list module that exactly meets the specifications given in the supplied header (.h) file. The playlist program must accept a filename on the command line (argv).

  Create program to input miles driven and gallons used

Create a program in C++ which will input miles driven and gallons used (both as integers) for each tankful. Program must compute and display the miles per gallon

  Write program to perform add-drop-list and update functions

Write C++ program to do add, drop, list (in last name / first name sorted order or id) and update functions. separate UI from data processing use object programming method multiple files

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd