Part 1 For this assignment call it assign0 Implement the fol
Part 1: For this assignment, call it assign0 Implement the following library and driver program under assign0: Your library will be consisting of myio.h and myio.c. The function prototypes as well as more explanations are listed in myio.h. Please download it and accordingly implement the exported functions in myio.c. Basically, you are asked to develop a simple I/O library which exports a few functions to simplify the reading of an integer, a double, and more importantly a string (whole line). In contrast to standard I/O functions that can read strings (e.g., scanf with \"%s\", fgets) into a given static size buffer, your function should read the given input line of characters terminated by a newline character into a dynamically allocated and resized buffer based on the length of the given input line. Also your functions should check for possible errors (e.g., not an integer, not a double, illigal input, no memory etc.) and appropriately handle them. Then write a driver program driver.c that can simply use the functions from myio library. Specifically, your driver program should get four command-line arguments: x y z output_filename. It then prompts/reads x many integers, y many doubles, and z many lines, and prints them into a file called output_filename.txt. Possible errors should be printed on stderr.
myio.h file
/*
* File: myio.h
* Version: 1.0
* -----------------------------------------------------
* This interface provides access to a basic library of
* functions that simplify the reading of input data.
*/
#ifndef _myio_h
#define _myio_h
/*
* Function: ReadInteger
* Usage: i = ReadInteger();
* ------------------------
* ReadInteger reads a line of text from standard input and scans
* it as an integer. The integer value is returned. If an
* integer cannot be scanned or if more characters follow the
* number, the user is given a chance to retry.
*/
int ReadInteger(void);
/*
* Function: ReadDouble
* Usage: x = ReadDouble();
* ---------------------
* ReadDouble reads a line of text from standard input and scans
* it as a double. If the number cannot be scanned or if extra
* characters follow after the number ends, the user is given
* a chance to reenter the value.
*/
double ReadDouble(void);
/*
* Function: ReadLine
* Usage: s = ReadLine();
* ---------------------
* ReadLine reads a line of text from standard input and returns
* the line as a string. The newline character that terminates
* the input is not stored as part of the string.
*/
char *ReadLine(void);
/*
* Function: ReadLine
* Usage: s = ReadLine(infile);
* ----------------------------
* ReadLineFile reads a line of text from the input file and
* returns the line as a string. The newline character
* that terminates the input is not stored as part of the
* string. The ReadLine function returns NULL if infile
* is at the end-of-file position. Actually, above ReadLine();
* can simply be implemented as return(ReadLineFile(stdin)); */
char *ReadLineFile(FILE *infile);
#endif
Solution
Below the myio.h is the driver created to read the values of the input data we can call the same in the simple program
File: myio.h
* Version: 1.0
* -----------------------------------------------------
* This interface provides access to a basic library of
* functions that simplify the reading of input data.
*/
#ifndef _myio_h
#define _myio_h
/*
* Function: ReadInteger
* Usage: i = ReadInteger();
* ------------------------
* ReadInteger reads a line of text from standard input and scans
* it as an integer. The integer value is returned. If an
* integer cannot be scanned or if more characters follow the
* number, the user is given a chance to retry.
*/
int ReadInteger(void);
/*
* Function: ReadDouble
* Usage: x = ReadDouble();
* ---------------------
* ReadDouble reads a line of text from standard input and scans
* it as a double. If the number cannot be scanned or if extra
* characters follow after the number ends, the user is given
* a chance to reenter the value.
*/
double ReadDouble(void);
/*
* Function: ReadLine
* Usage: s = ReadLine();
* ---------------------
* ReadLine reads a line of text from standard input and returns
* the line as a string. The newline character that terminates
* the input is not stored as part of the string.
*/
char *ReadLine(void);
/*
* Function: ReadLine
* Usage: s = ReadLine(infile);
* ----------------------------
* ReadLineFile reads a line of text from the input file and
* returns the line as a string. The newline character
* that terminates the input is not stored as part of the
* string. The ReadLine function returns NULL if infile
* is at the end-of-file position. Actually, above ReadLine();
* can simply be implemented as return(ReadLineFile(stdin)); */
char *ReadLineFile(FILE *infile);
#endif
Simple C program to obtain the integer, string and float values.
#include <stdio.h> // #include is a preprocessor directive to paste the code from the header file when necessary
# include <myio.h> // After creating the myio.c program we can call the function in header
int main()
{
char ch, int testinteger, float f, double lf; // Declaring the program
char str[100];
printf(“Enter the integer:\ ”);
scanf(\"%d\", & testInteger);
printf(“ Number = %d “, testinteger \ );
printf(“Enter the float value:”\ );
scanf(\"%f\", & f);
printf(“ Value = %f “, f\ ); // %f format string is used in case of floats
printf(\" Enter the Double value is %lf \ \", dbl);
scanf(\"%lf\", & dbl);
printf(“ Value =%lf”, dbl \ );
printf(\"Enter any character \ \"); // Format string %c is used in case of character types.
scanf(\"%c\", &ch);
printf(\"Entered character is %c \ \", ch);
printf(\"Enter any string ( upto 100 character ) \ \");
scanf(\"%s\", &str \ );
printf(\"Entered string is %s \ \", str);
}
Explanation of some important concepts.
printf() and scanf() functions are inbuilt library functions in C programming language which are available in C library by default. These functions are declared and related macros are defined in “stdio.h” which is a header file in C language.
PRINTF() FUNCTION IN C LANGUAGE:
In C programming language, printf() function is used to print the “character, string, float, integer, octal and hexadecimal values” onto the output screen.
We use printf() function with %d format specifier to display the value of an integer variable.
To generate a newline,we use “\ ” in C printf() statement.
SCANF() FUNCTION IN C LANGUAGE:
In C programming language, scanf() function is used to read character, string, numeric data from keyboard
Consider below example program where user enters a character. This value is assigned to the variable “ch” and then displayed.
Then, user enters a string and this value is assigned to the variable “str” and then displayed



