0% found this document useful (0 votes)
3 views1 page

Vector H

This document is a C header file that defines the 'vector_t' datatype and provides function prototypes for vector operations. It explains the purpose of header files in C, including how to include them and prevent multiple inclusions. The functions declared include creating, deleting, getting, and setting values in a vector.

Uploaded by

ali.pakistani246
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Vector H

This document is a C header file that defines the 'vector_t' datatype and provides function prototypes for vector operations. It explains the purpose of header files in C, including how to include them and prevent multiple inclusions. The functions declared include creating, deleting, getting, and setting values in a vector.

Uploaded by

ali.pakistani246
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#ifndef CS61C_VECTOR_H_

#define CS61C_VECTOR_H_
/* vector.h originally written by Jeremy Huddleston <[email protected]>
Sp2004
*
* So it looks like you've decided to venture into the "other" files of this
* lab. Good. C Header files (the .h extension) are a way of telling other .c
* files what they can have access to. You usually include stdlib.h in your
* C programs, and this process is identical to including this .h file with the
* one change being:
*
* #include "file.h"
* versus
* #include <file.h>
*
* The difference is that the <> notation is for system header files and the ""
* is for ones you provide yourself (in your local directory for instance).
*
* The header file starts off with
* #ifndef CS61C_VECTOR_H_
* #define CS61C_VECTOR_H_
*
* and ends with a final #endif. This prevents the file from being included
* more than once which could've possibly resulted in an infinite loop of
* file inclusions.
*
* First, we define the 'vector_t' datatype. This next line says that a 'vector_t'
* is the same as a 'struct vector_t'. So anywhere in the code after this, we
* can use 'vector_t *' to mean a pointer to a 'struct vector_t' (which is defined
in
* vector.c). We can get away with doing this even though we don't know what a
* struct vector is because all struct pointers have the same representation in
memory.
*/

#include <sys/types.h>

typedef struct vector_t vector_t;

/*
* Next, we provide the prototypes for the functions defined in vector.c. This
* is a way of telling the .c files that #include this header what they will
* have access to.
*/

/* Create a new vector */


vector_t *vector_new();

/* Free up the memory allocated for the passed vector */


void vector_delete(vector_t *v);

/* Return the value in the vector */


int vector_get(vector_t *v, size_t loc);

/* Set a value in the vector */


void vector_set(vector_t *v, size_t loc, int value);

#endif

You might also like