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.
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.
|