Read input for challenge 8

This commit is contained in:
Dimitri Lozeve 2020-06-11 19:09:30 +02:00
parent 099bb473ba
commit f59603e812
3 changed files with 242 additions and 0 deletions

36
src/ex08/main.c Normal file
View file

@ -0,0 +1,36 @@
#include "utils.h"
#include <stdio.h>
#define BUF_SIZE 1024
int main(int argc, char *argv[]) {
if (argc < 2) {
printf("Usage: %s <filename>\n", argv[0]);
return EXIT_FAILURE;
}
const char *filename = argv[1];
FILE *fp = fopen(filename, "r");
if (fp == NULL) {
printf("Error opening file %s\n", filename);
return EXIT_FAILURE;
}
char *line = NULL;
size_t line_length = 0;
ssize_t nread = 0;
while ((nread = getline(&line, &line_length, fp)) != -1) {
line[nread - 1] = '\0'; /* Remove the newline character */
unsigned char buf[BUF_SIZE] = {0};
size_t len = hex_to_bytes(buf, line);
}
free(line);
if (fclose(fp)) {
printf("Error closing file %s\n", filename);
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}