[Library] C to achieve arrays

zhaozj2021-02-16  73

----------- Array.h -----------

#ifndef array_h

#define array_h

#ifndef ERR

#define err -1

#define ok 1

#ENDIF

#ifndef min

#define min 0

#define max 100

#ENDIF

Typedef int stat;

TypedEf int ele mType;

Typedef struct {

ELMTYPE * IVA;

Int size;

Array;

Status array_init (array *, int);

Status W_Array (array *);

Status Print (array *);

ELMTYPE FIND (Array *, int);

#ENDIF

__________________ array.c __________________________

#include

#include

#include "array.h"

Status Array_init (Array * PEV, INT SZ = MAX)

{

PEV-> IVA =

(ELMTYPE *) Malloc (SZ * SIZEOF (ELMTYPE));

IF (! PEV-> IVA)

Return ERR;

PEV-> size = SZ;

Return OK;

}

Status W_Array (Array * OP)

{

IX;

IF (! OP)

Return ERR;

Printf ("Please enter% D number:", OP-> size);

For (ix = 0; ix size; ix)

Scanf ("% D", & op-> IVA [ix]);

Return OK;

}

Status Print (Array * OP)

{

IX;

IF (! OP)

Return ERR;

Printf ("is output% D number:", OP-> size);

For (ix = 0; ix size; ix)

Printf ("% D", OP-> IVA [ix]);

Printf ("/ n");

Return OK;

}

ELEMTYPE FIND (Array * OP, INT XI)

{

IF (! OP)

Return ERR;

Return OP-> IVA [xi];

}

转载请注明原文地址:https://www.9cbs.com/read-12381.html

New Post(0)