diff options
| author | ziejd2 | 2021-10-11 16:00:02 -0500 |
|---|---|---|
| committer | ziejd2 | 2021-10-11 16:00:02 -0500 |
| commit | 566a4de3fcc9b90da036dbf385044319c11a2b6a (patch) | |
| tree | 15c23be0643f41128f11cf9bb378ed505e259a6b /sourcecodes/k-best/src/files.c | |
| parent | a20784bad5cfa214ce23d16695d0064571bae9c3 (diff) | |
| parent | 73ba58868451b5fc6611e1feaa9b63f17b6cd19d (diff) | |
| download | BNW-566a4de3fcc9b90da036dbf385044319c11a2b6a.tar.gz | |
Resolved merge conflict
Diffstat (limited to 'sourcecodes/k-best/src/files.c')
| -rw-r--r-- | sourcecodes/k-best/src/files.c | 59 |
1 files changed, 0 insertions, 59 deletions
diff --git a/sourcecodes/k-best/src/files.c b/sourcecodes/k-best/src/files.c deleted file mode 100644 index 3227f63c..00000000 --- a/sourcecodes/k-best/src/files.c +++ /dev/null @@ -1,59 +0,0 @@ -#include <stdlib.h> -#include <stdio.h> -#include <string.h> - -#include "files.h" - -int nof_digits(int n) -{ - int c=0; - do { - c += 1; - n /= 10; - } while(n); - return c; -} - -int nof_lines(char* filename) { - int nof_lines = 0; - FILE* f = fopen(filename,"r"); - int c = 0; - while(EOF != (c=fgetc(f))) - if(c=='\n') ++nof_lines; - fclose(f); - return nof_lines; -} - -char* create_fn(char* dirname, int i, char* ext) -{ char* fn = malloc((strlen(dirname)+1+nof_digits(i)+strlen(ext)+1) - *sizeof(char)); - sprintf(fn,"%s/%d%s", dirname,i,ext); - return fn; -} - -FILE* open_file(char* dirname, int i, char* ext, char* mode) -{ - FILE* f; - char* fn = create_fn(dirname, i, ext); - sprintf(fn,"%s/%d%s", dirname,i,ext); - f = fopen(fn, mode); - free(fn); - return f; -} - -FILE** open_files(int nof_vars, char* dirname, char* ext, char* mode) -{ - FILE** files = malloc(nof_vars * sizeof(FILE*)); - int i; - for(i=0; i<nof_vars; ++i){ - files[i] = open_file(dirname, i, ext, mode); - } - return files; -} - -void free_files(int nof_vars, FILE** files){ - int i; - for(i=0; i<nof_vars; ++i) fclose(files[i]); - free(files); -} - |
