From e8f5e77dfc43f627a347fb5fa7247ae626b0002c Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Mon, 5 Feb 2024 16:39:24 +0100 Subject: [PATCH] add convert with argv one --- tools/convert.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tools/convert.c b/tools/convert.c index d797e88..1886348 100644 --- a/tools/convert.c +++ b/tools/convert.c @@ -10,14 +10,20 @@ int main(int argc, char* argv[]) blob.size = 0; FILE* fptr = NULL; size_t size = 0; - blob.data = malloc(sizeof(char)); + blob.data = NULL; - fptr = fopen("test.jpg", "r"); + fptr = fopen(argv[1], "r"); + if (fptr == NULL) { + printf("file %s not found\n", argv[1]); + exit(1); + } + + blob.data = malloc(sizeof(char)); while(fread(blob.data, sizeof(char), 1, fptr)) { blob.size++; } fseek(fptr, 0L, SEEK_SET); - printf("file size in bufs: %i\n", blob.size); + printf("file size of %s: %i byts\n", argv[1], blob.size); free(blob.data); blob.data = NULL; @@ -32,6 +38,7 @@ int main(int argc, char* argv[]) fptr = fopen("output.pnm", "w"); fwrite(output.data, output.size, 1, fptr); + printf("file size of output.pnm: %i bytes\n", output.size); fclose(fptr); fptr = NULL; -- 2.39.5