diff --git a/BuildDataBase.c b/BuildDataBase.c index 5a3806f378901330d25ab12eae2f2decc12346cc..75128b80412f9692271817d672f01aefe03dc3da 100644 --- a/BuildDataBase.c +++ b/BuildDataBase.c @@ -44,7 +44,7 @@ typedef struct { double* hotttnesss; } songs_struct; // Songs struct. -int test_file_bool = 0; // Check if using smaller test csv or not. +int test_file_bool = 1; // Check if using smaller test csv or not. int songs_array_max = ARRAY_SIZE; // Saves current size of songs array. int song_index = 0; // Current song index. songs_struct** songs_array; // The array which holds all song pointers. @@ -131,8 +131,8 @@ void read_file(int file_descriptor) { int offset_amount; size_t read_size; - read_buffer = calloc(BUFFER_SIZE, sizeof(char)); - temp_buffer = calloc(BUFFER_SIZE, sizeof(char)); + read_buffer = calloc(1, BUFFER_SIZE); + temp_buffer = calloc(1, BUFFER_SIZE); off_t read_value = read(file_descriptor, read_buffer, BUFFER_SIZE); if (read_value < 0) { @@ -174,7 +174,7 @@ void read_line(char *read_buffer, size_t read_size) { int line_index = 0; char *line_buffer; - line_buffer = calloc(BUFFER_SIZE, sizeof(char)); + line_buffer = calloc(1, BUFFER_SIZE); // Loop through entire chunk. while ((chunk_index < read_size) && (strcmp(&read_buffer[chunk_index], "\0") != 0)) { @@ -188,7 +188,7 @@ void read_line(char *read_buffer, size_t read_size) { // Free and reallocate memory for next line. free(line_buffer); - line_buffer = calloc(BUFFER_SIZE, sizeof(char)); + line_buffer = calloc(1, BUFFER_SIZE); } else { // Newline not found so save value and keep reading. line_buffer[line_index] = read_buffer[chunk_index]; @@ -214,7 +214,7 @@ void tokenize_line(char *line_buffer) { resize_array(); } - field_buffer = calloc(BUFFER_SIZE, sizeof(char)); + field_buffer = calloc(1, BUFFER_SIZE); songs_array[song_index] = calloc(1, sizeof(songs_struct)); while (strcmp(&line_buffer[line_index], "\0") != 0) { @@ -230,7 +230,7 @@ void tokenize_line(char *line_buffer) { //} free(field_buffer); - field_buffer = calloc(BUFFER_SIZE, sizeof(char)); + field_buffer = calloc(1, BUFFER_SIZE); } else { // No comma found. field_buffer[field_index] = line_buffer[line_index]; @@ -408,12 +408,12 @@ void save_line(int directory_descriptor, int binary_descriptor) { int* int_pointer; int index; int current_line_size = 0; - int name_size = ((strlen(songs_array[song_index]->song_name) * sizeof(char)) + 1); - int album_size = ((strlen(songs_array[song_index]->album_name) * sizeof(char)) + 1); - int artist_size = ((strlen(songs_array[song_index]->artist) * sizeof(char)) + 1); - int duration_size = (sizeof(float)); - int hotttnesss_size = (sizeof(double)); - int year_size = (sizeof(int)); + size_t name_size = ((strlen(songs_array[song_index]->song_name) * sizeof(char)) + 1); + size_t album_size = ((strlen(songs_array[song_index]->album_name) * sizeof(char)) + 1); + size_t artist_size = ((strlen(songs_array[song_index]->artist) * sizeof(char)) + 1); + size_t duration_size = (sizeof(float)); + size_t hotttnesss_size = (sizeof(double)); + size_t year_size = (sizeof(int)); int* current_line_size_ptr = ¤t_line_size; line_buffer = calloc(1, BUFFER_SIZE); @@ -497,10 +497,6 @@ void save_line(int directory_descriptor, int binary_descriptor) { *int_pointer = songs_array[song_index]->year[index]; ++int_pointer; - // write(1, "Buffer Value: ", 17); - // write(1, line_buffer, current_line_size); - // write(1, "\n\n", 3); - // Write buffer to file. write_size = write(binary_descriptor, line_buffer, current_line_size); if (write_size < current_line_size) { diff --git a/UseDataBase.c b/UseDataBase.c index 359946388a0bc0245308b54463686d93e2aafbaf..2470cf67f06e6e8ef6271fa4ab6314aadde984ee 100644 --- a/UseDataBase.c +++ b/UseDataBase.c @@ -46,7 +46,7 @@ typedef struct { double* hotttnesss; } songs_struct; // Songs struct. -int test_file_bool = 0; // Check if using smaller test csv or not. +int test_file_bool = 1; // Check if using smaller test csv or not. int songs_array_max = ARRAY_SIZE; // Saves current size of songs array. int song_index = 0; // Current song index. songs_struct** songs_array; // The array which holds all song pointers. @@ -358,7 +358,6 @@ void find_song(char* user_input_string) { songs_struct* search_array_by_song(songs_struct* return_song, int first_index, int last_index, char* desired_record) { - //songs_struct* return_song = calloc(1, sizeof(songs_struct*)); // Song to return. char* temp_string; // First check if this is the end of search or not.