SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 305 Weeks Ago, 2 Days Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Computer Science Posted 25 Dec 2017 My Price 10.00

Save the entire array ia into a file called 'filename'

hi, can anyone help me to write the main function for t1.c (attached file)?

#include "intarr.h"
#include <stdlib.h>
#include <stdio.h>

/**********************************************/
/*
 Save the entire array ia into a file called 'filename' in a binary
 file format that can be loaded by intarr_load_binary(). 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.
 */
int intarr_save_binary( intarr_t* ia, const char* filename )
{
    int *arr=ia->data;
    int n=ia->len;
    int i;
    FILE *p;
    p=fopen(filename,"wb");
    if(p!=NULL)
    {
        for(i=0;i<n;i++)
        {
           fwrite(&arr[i],sizeof(int), 1, p);
        }
        fclose(p);
        return 0;
    }
    return 1;
}
/*
 Load a new array from the file called 'filename', that was
 previously saved using intarr_save_binary(). Returns a pointer to a
 newly-allocated intarr_t on success, or NULL on failure.
 */
intarr_t* intarr_load_binary( const char* filename )
{
    FILE *p;
    p=fopen(filename,"rb");
    intarr_t *q;
    if(p!=NULL)
    {
        int init=(int)ftell(p);
        fseek(p,sizeof(int),SEEK_END);
        int k=(int)ftell(p);
        int n=(k-init-1)/sizeof(int);
        int x;
        q=intarr_create(n);
        int  count=0;
        rewind(p);
        while(fread(&x,sizeof(x),1,p)>0)
        {
            q->data[count++]=x;
        }
    }
    return q;
}

Answers

(5)
Status NEW Posted 25 Dec 2017 01:12 PM My Price 10.00

-----------  ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly

Not Rated(0)