ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

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

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 103 Weeks Ago, 3 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 26 Apr 2017 My Price 8.00

write the main function for t1.c

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

(11)
Status NEW Posted 26 Apr 2017 02:04 AM My Price 8.00

-----------

Not Rated(0)