From: Bastian Dehn Date: Mon, 5 Feb 2024 15:39:24 +0000 (+0100) Subject: add convert with argv one X-Git-Tag: v1.0.0^2~344^2~2 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=e8f5e77dfc43f627a347fb5fa7247ae626b0002c;p=sane-kds-s2000w-net.git add convert with argv one --- 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;