Initial commit, can read from a list of files passed.

This commit is contained in:
2021-12-28 20:09:33 +00:00
commit 5162804270
3 changed files with 50 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
#include <stdlib.h>
#include <stdio.h>
void print_file(char*);
int main(int argc, char* args[]) {
const char *input_files[argc - 1];
if (argc == 1) {
printf("Input files required.\n");
return -1;
}
// for (int i = 1; i < argc; i++) {
// input_files[i - 1] = args[i];
// print_file(args[i]);
// }
print_file(args[1]);
}
void print_file(char* file_path) {
FILE *file;
char* line = NULL;
size_t len = 0;
ssize_t bytes_read;
file = fopen(file_path, "r");
if (!file) {
printf("Failed to open '%s' for reading.\n", file_path);
return;
}
while((bytes_read = getline(&line, &len, file)) != -1) {
printf("%s", line);
}
printf("\n");
fclose(file);
if (line) free(line);
}