Skip to content

Instantly share code, notes, and snippets.

@jdarge
Last active April 28, 2024 16:37
Show Gist options
  • Save jdarge/ea1cba5d12522da112ec87911cbaf067 to your computer and use it in GitHub Desktop.
Save jdarge/ea1cba5d12522da112ec87911cbaf067 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
char* readFile(char* input) {
FILE* input_file = fopen(input, "r");
if(!input_file) return NULL;
fseek(input_file, 0, SEEK_END);
unsigned long input_file_size = ftell(input_file);
rewind(input_file);
unsigned long buffer = 16 - (input_file_size % 10);
char* input_text = (char*) malloc (input_file_size + buffer + 1);
fread(input_text, input_file_size, 1, input_file);
fclose(input_file);
input_text[input_file_size + buffer] = '\0';
return input_text;
}
int main(int argc, char **argv) {
if(argc != 2) return 1;
char* text = readFile(argv[1]);
if(!text) return 1;
printf("%s", text);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment