Question: Write a C program that Saves the entire array ia into a file called 'filename' in a JSON text file array file format that can
Write a C program that Saves the entire array ia into a file called 'filename' in a JSON text file array file format that can be loaded by intarr_load_json(). Returns zero on success, or a non-zero error code on failure. Arrays of length 0 should produce an output file containing an empty array.

Extend the functionality of your integer array from Lab 5to Support Saving and loading arrays from the filesystem in JSON, a common human- and machine-readable text format Sometimes itis useful for humans to be able to read your stored data. or to import you data into another program that does not understand your binary format. The most readable, portable XDR format is plain text. A popular syntax for text files is JSON JavaScript Object Notation which, as the name suggests, was originally an XDR format for web programs. It is easier to use and less verbose than the also-popular Extensible Markup Language XML and more expressive than the bare- bones Comma-Separated Values icSV) formats you may have seen The down side of text formats is that they are 1. inefficient in space, since eg.a four-byte integer (int32 t could require up to 12 bytes to represent its minimum value of-2147483647 as a decimal string 2. inefficent in time, since parsing the text file to convertitback into a binary format is much more expensive than loading a binary file The Standard library has two functions that can be very helpful forrendering text into files scanf They work just like the familiar printf and scanf but read to and write from FILE objects instead of standard input and standard output You should probably use these to solve this task. Notice from those man pages that another pair of functions snprintf() and sscanf is also available to print and scan from C strings too. (sprintf exists, but the lack of array length checking means this is not safe or secure to use. Always use snprintf()) The header e "inta also contain s these new function d eclarations: TASK 2. Save the entire array ia into a file called "filename in a JSON text file array file format that can be loaded intarr load ji Returns zero on success failure Arrays of length 0 should produce an output file code containing an empty array The JSON output should be human-readable Examples The following line is a valid JSON arra 100, 200, 300 The following lines are a v alid JSON array 100 200 300 int intarr save_j intarr. At' ia const chan filename json( ay from the file called 'filename Load a new al that was previously saved using intarr save The file may contain an array of length 0. Returns a pointer to a newly-allocated intarr t on even if that array has length 0), or NULL on failure intarr load json har filename intarrt const Requirements 1. Add and commit a single C source file called "t2.c" containing implementations of these two functions 2. The other requirements of Task 1 apply. Hint you should NOT create a single huge string in memory and write itoutin one call to write0. The string could require a huge amount of memory When your array is large. Since you chose an inemcient text format youre not optimizing for speed so don't worry about using many calls to write Extend the functionality of your integer array from Lab 5to Support Saving and loading arrays from the filesystem in JSON, a common human- and machine-readable text format Sometimes itis useful for humans to be able to read your stored data. or to import you data into another program that does not understand your binary format. The most readable, portable XDR format is plain text. A popular syntax for text files is JSON JavaScript Object Notation which, as the name suggests, was originally an XDR format for web programs. It is easier to use and less verbose than the also-popular Extensible Markup Language XML and more expressive than the bare- bones Comma-Separated Values icSV) formats you may have seen The down side of text formats is that they are 1. inefficient in space, since eg.a four-byte integer (int32 t could require up to 12 bytes to represent its minimum value of-2147483647 as a decimal string 2. inefficent in time, since parsing the text file to convertitback into a binary format is much more expensive than loading a binary file The Standard library has two functions that can be very helpful forrendering text into files scanf They work just like the familiar printf and scanf but read to and write from FILE objects instead of standard input and standard output You should probably use these to solve this task. Notice from those man pages that another pair of functions snprintf() and sscanf is also available to print and scan from C strings too. (sprintf exists, but the lack of array length checking means this is not safe or secure to use. Always use snprintf()) The header e "inta also contain s these new function d eclarations: TASK 2. Save the entire array ia into a file called "filename in a JSON text file array file format that can be loaded intarr load ji Returns zero on success failure Arrays of length 0 should produce an output file code containing an empty array The JSON output should be human-readable Examples The following line is a valid JSON arra 100, 200, 300 The following lines are a v alid JSON array 100 200 300 int intarr save_j intarr. At' ia const chan filename json( ay from the file called 'filename Load a new al that was previously saved using intarr save The file may contain an array of length 0. Returns a pointer to a newly-allocated intarr t on even if that array has length 0), or NULL on failure intarr load json har filename intarrt const Requirements 1. Add and commit a single C source file called "t2.c" containing implementations of these two functions 2. The other requirements of Task 1 apply. Hint you should NOT create a single huge string in memory and write itoutin one call to write0. The string could require a huge amount of memory When your array is large. Since you chose an inemcient text format youre not optimizing for speed so don't worry about using many calls to write
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
