INSTRUCTOR SUPPLIED SOURCE FILE:
#define INSTRUCTOR_FILE #ifdef INSTRUCTOR_FILE
#include #include
#define FILE_NAME_IX 1 // argv index for input file name #define TOTAL_ARGS 2 // number of command line arguments
void DisplayModifiedSingleReals(FILE *inFile); FILE *OpenFileBinary(const char *fileName);
int main(int argc, char *argv[]) { FILE *fp;
if (argc "); exit(EXIT_FAILURE); } fp = OpenFileBinary(argv[FILE_NAME_IX]); DisplayModifiedSingleReals(fp); fclose(fp); return EXIT_SUCCESS; } #endif
Cannot include the binary files here. Your help is deeply appreciated.
All the information i have is in the pictures, how more specific can i be?
C2A8E2 (10 points - Program) Exclude any existing source code files that may already be in your IDE project and add two new ones, naming them C2A8E2_OpenFileBinary.c and C2A8E2_Display Modified Single Reals.c. Also add instructor-supplied source code file C2A8E2_main-Driver.c. Do not write a main function! main already exists in the instructor-supplied file and it will use the code you write. A budding young computer scientist working at the local mini-mart has developed a slightly modified version of the IEEE 754 "Single Real" floating point format described in notes 16.10A-16.10C of the course book. The only difference between his version and the original is that the "Exponent" field occupies 9 bits and the "Fraction" field occupies 22 bits. These changes (shown in bold) are reflected in the following modified tables: Modified Single Real (32 Bits) 30 21 9-Bit 22-Bit Exponent Fraction Sign of Fraction Modified Single Real Normalized Numbers (limits: 1.5 10773.410-77) Zeros Bias of e +255 Range of e 0 Range of e Ocec 511 Mantissa 0.f = 0.0 Range off Any value Mantissa Infinities Value (-1). 1.. 2le-255) Range of e 511 Denormalized Numbers Mantissa 0.f = 0.0 (-limits: 18.2-10-84) Bias of e +254 NANS Range of e 0 Range of e 511 Range of Non- Range off Non- Mantissa 0.1 Value (-1'. 0.f2le 254 In order to test this modified format two instructor-supplied data files have been supplied, each of which must be placed in the program's "working directory". Each contains an assortment of 32-bit patterns, where these patterns represent various combinations of normalized numbers, denormalized numbers, zeros, infinities, and not-a-numbers (NANs). File C2A8E2_OpenFileBinary.c must contain a function named OpenFileBinary. OpenFileBinary syntax: FILE * OpenFileBinary(const char *fileName); Parameter: fileName -a pointer to the name of the file to be opened Synopsis: Opens the file named in fileName in the read-only binary mode. If the open fails an error message is output to stderr and the program is terminated with an error exit code. The error message must mention the name of the failing file. Return: A pointer to the FILE structure for the open file if the open succeeds; otherwise, the function does not return. File C2A8E2_DisplayModifiedSingleReals.c must contain function DisplayModifiedSingleReals. DisplayModifiedSingleReals syntax: void DisplayModifiedSingleReals(FILE *inFile); Parameter: inFile-a pointer to a FILE structure representing an open readable binary file Synopsis: This function assumes a byte is 8 bits and that the file in inFile: 1. was written in "big endian" format: 2. contains successive 32-bit patterns, each representing a "Modified Single Real". This function displays an aligned table in which each 32-bit pattern is represented by an 8-character hexadecimal value (letters may be uppercase or lowercase) followed by what that value represents if interpreted as a "Modified Single Real". That representation will always be preceded by a plus sign or a minus sign as appropriate. The possible representations are: 1. If a Normalized Number, a Denormalized Number, or a Zero is represented its magnitude will be displayed in scientific notation (using printf's %e conversion specification) followed by the word Normal, Denormal, or Zero, as appropriate: 2. If an infinity is represented INF will be displayed: 3. If a not-a-number is represented NAN will be displayed. If the file ends with an incomplete pattern (1.2 or 3 bytes) the exact message Unexpected EOF will be displayed at that point instead of the incomplete pattern. Return: void 1. Do not attempt to obtain a count of the total number of bytes in the file. 2. Do not attempt to read the entire contents of the file at once. 3. Do not make any assumptions about or attempt to determine the machine's "endianness"; a properly written program does not need to know. 4. Do not make any assumptions about the maximum number of bytes in any data types other than the char types. For example, you may not assume type long has only 4 bytes. 5. If you use a structure or a class (neither of which is necessary), do not make any assumptions about padding or whether bit fields are allocated left-to-right or right-to-left. 6. Although you may assume a byte is 8 bits, if you actually need to represent that number use the standard library CHAR_BIT macro, not something you define. Manually run your program twice - once with instructor-supplied input file TestFile7.bin and once with instructor-supplied input file TestFile8.bin, each of which must be placed in the program's "working directory". Specify the desired file name on the command line - DO NOT prompt the user for it or place it in your code. Your display must be in the format shown below, where the number of exponent digits actually displayed (typically 2 or 3) will vary by implementation. This example represents the first 12 patterns from file TestFile7.bin. The EOF message at the end of the display must occur if and only if a file ends with an incomplete pattern: Oxffc00001 ex7fffffff +NAN exffc00000 -INF @x7fc00000 +INF exffbfffff -1.157921e+77 Normal @x7fbfffff +1.157921e+77 Normal @x80400000 -3.454467e-77 Normal -NAN Ox00400000 +3.454467e-77 Normal 0x80000001 -8.236092e-84 Denormal 0x003fffff +3.454467e-77 Denormal Ox000doa0o +7.037971e-78 Denormal ex80000000 -0.000000e+00 Zero Unexpected EOF Hints: Read each 4-byte group from the input file into a 4-element unsigned char array and use a loop to place those 4 bytes into the appropriate bytes of a single unsigned long variable. Do all necessary masking and testing on that variable. C2A8E2 (10 points - Program) Exclude any existing source code files that may already be in your IDE project and add two new ones, naming them C2A8E2_OpenFileBinary.c and C2A8E2_Display Modified Single Reals.c. Also add instructor-supplied source code file C2A8E2_main-Driver.c. Do not write a main function! main already exists in the instructor-supplied file and it will use the code you write. A budding young computer scientist working at the local mini-mart has developed a slightly modified version of the IEEE 754 "Single Real" floating point format described in notes 16.10A-16.10C of the course book. The only difference between his version and the original is that the "Exponent" field occupies 9 bits and the "Fraction" field occupies 22 bits. These changes (shown in bold) are reflected in the following modified tables: Modified Single Real (32 Bits) 30 21 9-Bit 22-Bit Exponent Fraction Sign of Fraction Modified Single Real Normalized Numbers (limits: 1.5 10773.410-77) Zeros Bias of e +255 Range of e 0 Range of e Ocec 511 Mantissa 0.f = 0.0 Range off Any value Mantissa Infinities Value (-1). 1.. 2le-255) Range of e 511 Denormalized Numbers Mantissa 0.f = 0.0 (-limits: 18.2-10-84) Bias of e +254 NANS Range of e 0 Range of e 511 Range of Non- Range off Non- Mantissa 0.1 Value (-1'. 0.f2le 254 In order to test this modified format two instructor-supplied data files have been supplied, each of which must be placed in the program's "working directory". Each contains an assortment of 32-bit patterns, where these patterns represent various combinations of normalized numbers, denormalized numbers, zeros, infinities, and not-a-numbers (NANs). File C2A8E2_OpenFileBinary.c must contain a function named OpenFileBinary. OpenFileBinary syntax: FILE * OpenFileBinary(const char *fileName); Parameter: fileName -a pointer to the name of the file to be opened Synopsis: Opens the file named in fileName in the read-only binary mode. If the open fails an error message is output to stderr and the program is terminated with an error exit code. The error message must mention the name of the failing file. Return: A pointer to the FILE structure for the open file if the open succeeds; otherwise, the function does not return. File C2A8E2_DisplayModifiedSingleReals.c must contain function DisplayModifiedSingleReals. DisplayModifiedSingleReals syntax: void DisplayModifiedSingleReals(FILE *inFile); Parameter: inFile-a pointer to a FILE structure representing an open readable binary file Synopsis: This function assumes a byte is 8 bits and that the file in inFile: 1. was written in "big endian" format: 2. contains successive 32-bit patterns, each representing a "Modified Single Real". This function displays an aligned table in which each 32-bit pattern is represented by an 8-character hexadecimal value (letters may be uppercase or lowercase) followed by what that value represents if interpreted as a "Modified Single Real". That representation will always be preceded by a plus sign or a minus sign as appropriate. The possible representations are: 1. If a Normalized Number, a Denormalized Number, or a Zero is represented its magnitude will be displayed in scientific notation (using printf's %e conversion specification) followed by the word Normal, Denormal, or Zero, as appropriate: 2. If an infinity is represented INF will be displayed: 3. If a not-a-number is represented NAN will be displayed. If the file ends with an incomplete pattern (1.2 or 3 bytes) the exact message Unexpected EOF will be displayed at that point instead of the incomplete pattern. Return: void 1. Do not attempt to obtain a count of the total number of bytes in the file. 2. Do not attempt to read the entire contents of the file at once. 3. Do not make any assumptions about or attempt to determine the machine's "endianness"; a properly written program does not need to know. 4. Do not make any assumptions about the maximum number of bytes in any data types other than the char types. For example, you may not assume type long has only 4 bytes. 5. If you use a structure or a class (neither of which is necessary), do not make any assumptions about padding or whether bit fields are allocated left-to-right or right-to-left. 6. Although you may assume a byte is 8 bits, if you actually need to represent that number use the standard library CHAR_BIT macro, not something you define. Manually run your program twice - once with instructor-supplied input file TestFile7.bin and once with instructor-supplied input file TestFile8.bin, each of which must be placed in the program's "working directory". Specify the desired file name on the command line - DO NOT prompt the user for it or place it in your code. Your display must be in the format shown below, where the number of exponent digits actually displayed (typically 2 or 3) will vary by implementation. This example represents the first 12 patterns from file TestFile7.bin. The EOF message at the end of the display must occur if and only if a file ends with an incomplete pattern: Oxffc00001 ex7fffffff +NAN exffc00000 -INF @x7fc00000 +INF exffbfffff -1.157921e+77 Normal @x7fbfffff +1.157921e+77 Normal @x80400000 -3.454467e-77 Normal -NAN Ox00400000 +3.454467e-77 Normal 0x80000001 -8.236092e-84 Denormal 0x003fffff +3.454467e-77 Denormal Ox000doa0o +7.037971e-78 Denormal ex80000000 -0.000000e+00 Zero Unexpected EOF Hints: Read each 4-byte group from the input file into a 4-element unsigned char array and use a loop to place those 4 bytes into the appropriate bytes of a single unsigned long variable. Do all necessary masking and testing on that variable