You will write a C program (location: task-2/solution-2.c) that will take two command line arguments. The first command line argument will be the name of the input file and the second command line argument will be the name of the output file.

Input: The input file will contain a sequence of hexadecimal numbers: one in each line followed by a terminating newline character (i.e., '\n). Each hexadecimal number will have digits from the following set: D = {0, 1, 2, . . . , 9, a, b, c, d, e, f}. Each input line will have the digits of an hexadecimal number printed in ASCII format. For instance, digit 0 will be character 0, digit 1 will be 1, and similarly, digit a will be character a and so on. Note that the input hexadecimal number can have leading zeros.

Assumptions: You can safely assume that each input line will have a maximum of 1024 characters including the newline character at the end of the line.

Output: For each hexadecimal number in the input file, you should print a line in the output file. The line should contain the corresponding binary representation of the hexadecimal number followed by a newline character (i.e., '\n). The binary number should be printed using ASCII characters: 0s and 1s. You should not remove the leading zeros from the binary representation of the hexadecimal number while printing to the output file.

Error checking: Your program should do appropriate error checking. In case of an error, your program must print the following error message: "An error has occurred\n" and then exit with the error code 1, e.g., using exit(1).

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.