#include #include int *getinp(const char *filename); int main(int argc, char *argv[]) { if (argc != 2) { fprintf(stderr, "Usage: %s \n", argv[0]); exit(EXIT_FAILURE); } int *foo = getinp(argv[1]); return 0; } int *getinp(const char *filename) { FILE *fd = fopen(filename, "r"); if (fd == NULL) { fprintf(stderr, "Couldn't open %s for reading\n", filename); exit(EXIT_FAILURE); } int pos = 0; int size = 64; int *arr = malloc(size * sizeof(int)); if (arr == NULL) { fprintf(stderr, "Not enough memory\n"); exit(EXIT_FAILURE); } char c; while ((c = fgetc(fd)) != EOF) { arr[pos] = c; pos++; if (pos >= (size - 1)) { size *= 2; if (realloc(arr, size * sizeof(int)) == NULL) { fprintf(stderr, "Not enough memory\n"); exit(EXIT_FAILURE); } } } arr[pos] = '\0'; fclose(fd); return arr; }