diff options
Diffstat (limited to 'input.c')
-rw-r--r-- | input.c | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -40,6 +40,20 @@ void input_int_read(struct input_int* result, char* filename) { fclose(file); } +int str_replace(char* string, char a, char b) { + size_t i = 0; + int replace_count = 0; + while(string[i] != '\0') { + if(string[i] == a) { + string[i] = b; + replace_count++; + } + i++; + } + + return replace_count; +} + void input_str_read(struct input_str* result, char* filename) { // open input file FILE* file=fopen(filename, "r"); @@ -57,6 +71,9 @@ void input_str_read(struct input_str* result, char* filename) { char** dst = &(result->lines[lineIndex]); if(getline(dst, &lineSize, file) < 0) err(1, "read error line %ld\n", lineIndex); + + // cleanup line end char + str_replace(result->lines[lineIndex], '\n', '\0'); } fclose(file); |