Roxy N.

asked • 11/30/20

Write a C program that implements a simplistic version of the linux cut command.

Write a C program in 3 files as follows:

a11.c -main function

a1funcs.c -functions used by main

a1funcs.h -prototypes for functions defined in assign2funcs.c


Your program implements a simplistic version of the Linux cut command.

-it only cuts FIELDS (not characters, bytes, etc).

-it requires between 1 and 100 fields (inclusive)

-it requires fields to be unique, and specified in increasing order

-it does not implement any functionality of cut other than cutting

fields with given input delimiter and output delimiter

-the format of its command line arguments are simpler than cut's


DO NOT call the cut command itself, nor any other Linux command from

your code (e.g., with a system call).


Your program expects command line arguments specifying the

following, in this order:

-input delimiter (a single character)

-output delimiter (a single character)

-field(s) (at least one, and at most 100, unique positive integers,

given in increasing order of size)


If CLAs are not as required above, print the following message on

stderr and exit with exit code 1:

a.out: specify input_delimiter output_delimiter and 1-100 fields in order

Note that in the above error message, the following are NOT hard-coded,

but are obtained from appropriate arguments: "a.out", "100". Also,

"a.out" must be obtained from argv[0] and "100" must be from a

#define preprocessor directive.


If the program run does not result in error, exit with exit code 0.


Your program reads input from stdin only, with fields separated by a

single input delimiter. Your program writes output to stdout (and error message to stderr).

For each line of input, your program displays the required fields

on stdout using the output delimiter to separate fields.


Your main function must be in assign2.c. You must write & use

appropriate additional functions, with their declarations and

definitions in files assign2funcs.h and assign2funcs.c,

respectively. The program will be compiled as follows:

> gcc assign2.c assign2funcs.c


Your program must produce the same output as the Linux cut command

does for "the same" input. E.g., the following two must produce

identical output (files "actual" and "expected" must be identical):

>a.out , . 16 17 25 actual

>cut -d, --output-delimiter=. -f16,17,25 expected


Must write in C.


1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.