vector.txt

来自「dos 1.0 其中包含quick basic源代码、内存管理himem emm」· 文本 代码 · 共 70 行

TXT
70
字号
SUMMARY VectorAlloc fAppendVector

#include <tools.h>

struct vectorType {
    int max;                            /* max the vector can hold           */
    int count;                          /* count of elements in vector       */
    unsigned elem[1];                   /* elements in vector                */
};

struct vectorType *VectorAlloc(cElem)
int cElem;

flagType fAppendVector(ppVec, uElem)
struct vectorType **ppVec;
unsigned int uElem;

DESCRIPTION

VectorAlloc allocates a vector large enough to hold cElem elements.

fAppendVector adds an element to a vector.  If the vector is full, a new
larger vector is allocated, the old vector elements are copied, new appended
and old vector deallocated.  If ppVec is NULL a vector of default length
is allocated.

RETURN VALUE

VectorAlloc returns NULL if the vector could not be allocated else returns
pointer to vector.

fAppendVector zero if the element was not appended otherwise non-zero.
*ppVec is updated of a new vector is allocated.

IMPLEMENTATION


SEE ALSO


NOTE


EXAMPLE

#include <tools.h>

#define BUFLEN 256

main(c, argv)
int c;
char *argv[];
{
    FILE *pFile;
    struct vectorType *pVec;
    char strLine[BUFLEN];
    int i;

    pVec = VectorAlloc(1);
    if ((pFile = swopen("$USER:\\tools.ini", "to"))) {
        while (swread(strLine, BUFLEN, pFile) &&
             fAppendVector(&pVec, MakeStr(strLine)))
            ;
        swclose(pFile);
        printf("Contents of $USER:\\tools.ini section [to]\n");
        for (i=0; i< pVec->count; i++)
            printf("%3d \"%s\"\n", i, (char *) pVec->elem[i]);
        }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?