Question
The Lab04.c source program consists of the following four(4) subprograms: 1. int read_text(char *p_text[], FIle *fp): This function is called by the main
The "Lab04.c" source program consists of the following four(4) subprograms:
1. int read_text(char *p_text[], FIle *fp):
This function is called by the main program to read the input "text.txt" file, line by line, and return the entire text in the array of pointers: char *p_text[MAX_NUM_LINES]. Please read the documentation in the source code of the function for details. The code for this function is given and no modifications are required by you.
2. void write_text_inorder(char *p_text[], nlines):
This subroutine takes the "p_text" array of pointers as argument, and the number of lines it contains (nlines). The subroutine prints the contents of the pointer array in the same order that it was input by the "read_text" function. Please read the documentation in the source code of the subroutine for details.
Task: The subroutine header is given, you are to write the body. Note: If there are no lines of text to print, you must output a message to that affect using the "MSG_INFO" enumerated message type and the report_message(...) routine.
3. void write_text_reverse(char *p_text[], nlines):
This subroutine takes the "p_text" array of pointers as argument, and the number of lines it contains (nlines). The subroutine prints the contents of the pointer array in the REVERSE order that it was input by the "read_text" function. That is, the last input line of text is printed first, the second-last input line is printed second, and so on. Please read the documentation in the source code of the subroutine for details.
The subroutine header is given, you are to write the body. Note: If there are no lines of text to print, you must output a message to that affect using the "MSG_INFO" enumerated message type and the report_message(...) routine.
4. void report_message(char msg[MAX_MSG_NUM][MAX_MSG_LNG], enum msg_kind_type msg_kind ):
This routine prints a given message, "msg", in a standardized format with each message type having a unique message prefix to identify the message on output. For example, an information message (MSG_INFO) has a prefix of "::> MSG: ", while an error message (MSG_ERROR) has a prefix of ">>> ERR: ". Please read the documentation in the source code of the subroutine for details.
Your task is to create a NEW enumerated message type/kind called "MSG_END", and use it to print the "Program Terminated. Have a great day." message in a standardized fashion using the report_message(...) routine.
The output message MUST look like this:
The message in-order The message in-reverse order ==> END: Program Terminated. : Have a great day.
ha_library.h
#ifndef HA_LIBRARY_H_
#define HA_LIBRARY_H_
// Define machine-independent TRUE and FALSE values
#ifdef TRUE
#undef TRUE
#undef FALSE
#endif
#define TRUE (1==1)
#define FALSE (0==1)
//===== GLOBAL MACRO DEFINITIONS ================================================================
#define NL " " // New Line string
#define cNL ' ' // New Line char
#define LF " " // Line Feed string
#define cLF ' ' // Line Feed char
#define CR " " // Carriage Return string
#define cCR ' ' // Carriage Return char
#define CRLF " " // Carriage Return/Line Feed
#define LFCR " " // Line Feed/Carriage Return
#define FF "\f" // Form Feed
#define NUL "\0" // Null string
#define cNUL '\0' // Null character
#define BLK " " // Single Blank string
#define cBLK ' ' // Single Blank character
#define cUScore '_' // Underscore character
#define UScore "_" // Underscore string.
#define cZERO '0' // Single ZERO character
#define HTAB "\t" // Horizontal Tab string
#define cHTAB '\t' // Horizontal Tab character
#define VTAB "\v" // Vertical Tab string
#define cVTAB '\v' // Vertical Tab character
#define ESC "\x1B" // Escape string [hex(1B) = dec(27)]
// ===== GLOBAL STATEMENT FUNCTION DEFINITIONS ====================================================================
#define F_MIN(v1,v2) (((v1) < (v2))? (v1):(v2)) // Return the less of v1 and v2
#define F_MAX(v1,v2) (((v1) > (v2))? (v1):(v2)) // Return the greater of v1 and v2
#define ZF_MIN(v1,v2) (F_MAX(0, (F_MIN((v1),(v2))))) // Like F_MIN, but lower bounds the result at ZERO
#define ZF(v) (F_MAX(0, (v))) // Lower bounds the value "v" at ZERO.
#define F_NOT(v) (((v) == TRUE)? FALSE:TRUE) // Logical Negation.
#define F_ABS(v) (((v) >= 0 )? (v):(-(v))) // Absolute value
//===== GLOBAL Constants ==========================================================================================
#define MAX_NUM_LINES 500 // Max. number of lines.
#define MAX_LINE_LNG 81 // Max. length of line. One extra byte for terminating null.
#define MAX_MSG_NUM 10 // Number of message lines.
#define MAX_MSG_LNG 133 // Length of a message string: Max of 132 chars +1 for terminating null byte.
//===== GLOBAL VARIABLES and STRUCTURE DEFINITIONS ================================================================
char msg[MAX_MSG_NUM][MAX_MSG_LNG]; // Message buffer. Can hold MAX_MSG_NUM messages, each MAX_MSG_LNG chars long.
// MESSAGE type or kind of message.
enum msg_kind_type{MSG_INFO, // Information.
MSG_WARNING, // Warning.
MSG_ERROR, // Error.
MSG_END}; // Program end.
#endif /* HA_LIBRARY_H_ */
text.txt
Alex "M 41 74 170 120 jefferson st. Riverside NJ 8075,
Bertm "M" 42 68 166 220 hobo Av. Phila PA 9119,
Carl "M" 32 70 155 120 Jefferson St. Riverside NJ 8075,
Dave "M" 39 72 167 7452 Terrace "At the Plaza" road SomeTown SD 91234,
Elly F" 30 66 124 SomeTown SD 298,
Fran "F" 33 66 115 9th, at Terrace plc Desert City CO 123,
Gwen "F" 26 64 121 120 jefferson st. Riverside NJ 8075,
Hank "M" 30 71 158 220 hobo Av. Phila PA 9119,
Ivan "M" 53 72 175 120 Jefferson St. Riverside NJ 8075,
Jake "M" 32 69 143 7452 Terrace "At the Plaza" road SomeTown SD 91234,
Kate "F" 47 69 139 SomeTown SD 298,
Luke "M" 34 72 163 9th, at Terrace plc Desert City CO 123,
Myra "F" 23 62 98 120 jefferson st. Riverside NJ 8075,
Neil "M" 6 75 160 220 hobo Av. Phila PA 9119,
Omar "M" 38 70 145 120 Jefferson St. Riverside NJ 8075,
Page "F" 31 67 135 7452 Terrace "At the Plaza" road SomeTown SD 91234,
Quin "M" 29 71 176 SomeTown SD 298,
Ruth "F" 28 65 131 9th, at Terrace plc Desert City CO 123.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started