You are asked to make a program in C that calculates the differences between two text files. The specifications of the program are as follows:
-
The program receives as input the name of two text files, henceforth referred to as F1 and F2, and a set of options, listed in Step 3.
-
The program, once started, loads the two text files into memory in blocks of 50 lines, which are processed before reading the next lines of the file.
-
The program calculates the diff between the i-th line of file F1 and the i-th line of file F2, returning an output that depends on the options passed from the command line, which are
- -g: if F1 and F2 are different in at least one line returns the string
F1 and F2 are different
. The names of the processed files should be returned instead of F1 and F2. - -s: if F1 and F2 are equal in all rows returns the string
F1 and F2 are equal
. The names of the processed files should be returned instead of F1 and F2. - -d: returns the numbers of different rows
- -u: returns the numbers of the equal rows
- -v: combined with -d or -u prints lines that differ or are the same. The
output format must be
#Line, FILENAME F1: <F1 line that differs or is the same> #Line, FILENAME F2: <F2 line that differs or is the same>
- -o FILENAME_OUTPUT: redirects the output to a text file.
- -g: if F1 and F2 are different in at least one line returns the string
The -g and -s options can be combined; the -d and -u options are mutually exclusive; the -o option can always be used.
- In case the two files have different lengths, in case the -d, -u and -v options, the comparison must be made for the number of rows contained in the smaller file (the one with the smallest number of rows).
The program should work properly in the following cases:
- The input consists of two equal rows (test with 5 different pairs of rows of lengths greater and less than 50 rows)
- The input consists of two different files (test with 5 different pairs of files of lengths greater and less than 50 lines)
- Both input files, or either one, does not exist
- One of the two input files is empty
- The two input files have different lengths (test with 5 different pairs of files)
You are asked to realize, with the C language, a server program (henceforth server) and a client program (henceforth client) that meet the following specifications:
- The server receives requests from remote clients via a TPC/IP socket
- The client requires the server to perform an arithmetic operation and return the result. The requests made by clients thus contain an arithmetic operation and its operands
- The server calculates the requested operation and returns the result to the client via socket TCP/IP. Additional detail specifications are:
- The operations that the server must be able to calculate are: +, -, *, /
- The message sent by the client has the following structure
[operation, Operand1, Operand2]
- The response message sent from the server to the client has the following structure
[timestamp receiving request, timestamp sending response, operation result]
- The server must be able to handle multiple clients concurrently, i.e., it is multithreaded
- The server writes into a single log the operations performed, results, timestamps, id of the client (e.g., IP address). Concurrent access to the log must be guaranteed and managed.
- The client must allow the user to enter an operation by means of a string such as.
Operando1 operation Operando2
. - The client must transform the input string into the specified message format
- When the client receives a response to a request, it must display the result
of the operation and the service time, i.e.
timestamp sending response - timestamp receiving request
- The client, once activated, must allow as many operations to be entered as the user wishes, until explicitly terminated by the client itself. The user, cannot request a new operation before receiving a response to the previous request.
NOTE: implementation of a graphical user interface is not required.
The program should work properly in the following cases:
- A + B, A - B, A * B, A/B where A and B are real numbers other than 0 (calculate at least 5 operations for each operator)
- A/B, where B is' zero.
- The user-supplied input string is not correctly formatted, i.e., one of the operands is missing or is not a number, the operator is absent or is not one of the provided
- The client process can't connect to the server process because, for example, the server is not active
- Server process terminates unexpectedly