You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			38 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			C
		
	
			
		
		
	
	
			38 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			C
		
	
#include "file_array.h"
 | 
						|
#include "stdbool.h"
 | 
						|
 | 
						|
void file_array_free(file_array_t* file_array) {
 | 
						|
  	fclose(file_array->fp);
 | 
						|
	free(file_array);  
 | 
						|
}
 | 
						|
 | 
						|
file_array_t* file_array_create(char* filename, size_t total_size) {
 | 
						|
    file_array_t* file_array = (file_array_t*)malloc(sizeof(file_array_t));
 | 
						|
 | 
						|
    file_array->fp = fopen(filename, "w+");
 | 
						|
 | 
						|
    if (file_array == NULL || file_array->fp == NULL) {
 | 
						|
        return NULL;
 | 
						|
    }
 | 
						|
 | 
						|
    file_array->init_pos = 0;
 | 
						|
    file_array->total_size = total_size;
 | 
						|
    return file_array;
 | 
						|
}
 | 
						|
 | 
						|
void file_array_read(file_array_t* file_array) {
 | 
						|
    rewind(file_array->fp);
 | 
						|
    file_array->init_pos = 0;
 | 
						|
}
 | 
						|
 | 
						|
bool file_array_get(file_array_t* file_array, size_t pos, double *valor) {
 | 
						|
	fseek(file_array->fp, pos * sizeof(double), SEEK_SET);
 | 
						|
    fread(valor, sizeof(double), 1, file_array->fp);
 | 
						|
    return true;
 | 
						|
}
 | 
						|
 | 
						|
bool file_array_save(file_array_t* file_array, size_t pos, double valor) {
 | 
						|
	fseek(file_array->fp, pos * sizeof(double), SEEK_SET);
 | 
						|
    fwrite(&valor, sizeof(double), 1, file_array->fp);
 | 
						|
	return true;
 | 
						|
} |