Question: Given: typedef struct { int* data; unsigned int len; } intarr_t; We have to write following two functions. We can use fscanf(), fprintf(), snprintf(), ssanf().
Given: typedef struct { int* data; unsigned int len; } intarr_t;
We have to write following two functions. We can use fscanf(), fprintf(), snprintf(), ssanf().
1.) int intarr_save_json( intarr_t* ia, const char* filename ); (In this function, Save the entire array ia into a file called 'filename' in a JSON text file array file format. 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. The JSON output should be human-readable. Examples:
The following line is a valid JSON array: [ 100, 200, 300 ]
The following lines are a valid JSON array: [ 100, 200, 300 ] )
2.) intarr_t* intarr_load_json( const char* filename ); ( In this function, Load a new array from the file called 'filename', 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 success (even if that array has length 0), or NULL on failure.)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
