So i'm trying to figure out how to do a few different things and I haven't worked with C that much, so any help would be much appreciated.
typedef int data_t;
typedef struct set {
data_t *array;
size_t capacity;
size_t size;
} set_t;
typedef data_t* set_i_t;
#define CLEAR -1
I have gotten this method working which uses malloc and allocates memory:
int set_init( set_t *set, int capacity ){
set->array = (data_t*)malloc(capacity * sizeof(data_t));
if(set->array == NULL){
return 1;
}
else{
set->capacity = capacity;
set->size = 0;
return 0;
}
}
And a method which frees it:
void set_free( set_t *set ){
free(set->array);
set->array = NULL;
set->capacity = set->size = 0;
}
In a separate method i'm trying to set all the values in the set to -1 (CLEAR)
void set_clear( set_t *set){
int i = 0;
for (i = 0; i < set->size; i++){
set->array = CLEAR;
}
set->size = 0;
}
Return the Size of the set:
int set_size( set_t set ) {
return sizeof(set->array);
}
Return the capacity:
int set_capacity( set_t set ) {
int capacity = set->capacity;
return capacity;
}
And then print the set:
void set_print( set_t set ) {
//Honestly don't feel like i'm ready for this one yet.
}
If anyone could walk me through a couple of these or give me a little assistance on how these can work, that would be awesome. Thanks guys!