I am trying to write a program to use these functions from the header BV.h. I keep getting an error when trying to use setBit, clrBit, valBit, and printV.
I believe it has to do with the [pos] part of the code, but I am not really sure.
bv.c
//bv.c
#include <stdio.h>
#include "bv.h"
#include <stdlib.h>
bitV* newVec(uint32_t length){
bitV* v = malloc(sizeof(bitV));
(*v).l = length;
return v;
}
void delVec(bitV* v){
free(v);
// *v = NULL;
}
void oneVec(bitV* v){
for(int i = 0;(unsigned)i < (v->l); i++){
(*v).head = 1;
}
}
void setBit(bitV* v, uint32_t pos){
(*v).head[pos] = 1;
}
void clrBit(bitV* v, uint32_t pos){
v->head[pos] = 0;
}
uint8_t valBit(bitV* v, uint32_t pos){
return v->head[pos];
}
uint32_t lenVec(bitV* v){
return v->l;
}
void printV(bitV* v){
for(int i = 0;(unsigned) i < (v->l); i++){
printf("%d\n",valBit(v,i));
}
}
bv.h
// bv.h — Bit Vector interface
# ifndef _BVector
# define _BVector
# include <stdint.h>
typedef struct bitV {
uint8_t *head;
uint32_t l;
} bitV;
bitV *newVec(uint32_t);
void delVec(bitV *);
void oneVec(bitV *);
void setBit(bitV *, uint32_t);
void clrBit(bitV *, uint32_t);
uint8_t valBit(bitV *, uint32_t);
uint32_t lenVec(bitV *);
void printV(bitV *);
# endif