From c76d918820fe88de85fc925c7d643d3c6d4a3fbb Mon Sep 17 00:00:00 2001 From: iliya <iliya.saroukha@hes-so.ch> Date: Fri, 10 Nov 2023 13:42:15 +0100 Subject: [PATCH] fix: moved implementation of printing to stdout an int to the main program --- struct/vec.c | 13 ------------- struct/vec.h | 5 +---- vec_test.c | 15 +++++++++++++-- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/struct/vec.c b/struct/vec.c index 44ace6d..510c08e 100644 --- a/struct/vec.c +++ b/struct/vec.c @@ -256,19 +256,6 @@ void vec_remove(vec_t *vec, size_t idx) { free(aftr_idx); } -char *print_int(void *element) { - int64_t data = (int64_t)element; - char *s = calloc(30, sizeof(char)); - - if (s == NULL) { - perror("calloc"); - return NULL; - } - - sprintf(s, "Data: %ld |\n", data); - return s; -} - /** * @brief Function that prints out the content as well as the current length and * capacity of a given vector diff --git a/struct/vec.h b/struct/vec.h index 7ca9003..becc2a7 100644 --- a/struct/vec.h +++ b/struct/vec.h @@ -1,5 +1,4 @@ -#ifndef _VEC_H_ -#define _VEC_H_ +#pragma once #include <stdbool.h> #include <stdint.h> @@ -27,5 +26,3 @@ extern char *print_int(void *element); extern void vec_print(vec_t *vec, char *(*print_entry)(void *data)); extern void vec_destroy(vec_t **vec); - -#endif diff --git a/vec_test.c b/vec_test.c index b497f98..d220a25 100644 --- a/vec_test.c +++ b/vec_test.c @@ -7,7 +7,6 @@ #define NB_OPTIONS 6 void print_menu(void) { - fprintf(stdout, "*********** Menu opts ***********\n"); fprintf(stdout, "1:\tPush number\n"); fprintf(stdout, "2:\tDelete at given index\n"); @@ -18,6 +17,19 @@ void print_menu(void) { fprintf(stdout, "*********************************\n\n"); } +char *print_int(void *element) { + int64_t data = (int64_t)element; + char *s = calloc(30, sizeof(char)); + + if (s == NULL) { + perror("calloc"); + return NULL; + } + + sprintf(s, "Data: %ld |\n", data); + return s; +} + int main(int argc, char **argv) { if (argc < 2) { fprintf(stderr, "Usage:\n"); @@ -84,7 +96,6 @@ int main(int argc, char **argv) { item_poped); break; case 4: - // vec_print(new_vec); vec_print(new_vec, print_int); break; case 5: -- GitLab