diff options
author | Vincent Douillet <vincent@vdouillet.fr> | 2021-12-12 08:42:25 +0100 |
---|---|---|
committer | Vincent Douillet <vincent@vdouillet.fr> | 2021-12-12 08:42:25 +0100 |
commit | 1c352d8c1dc97c8f6f11b7fbf38c621f53b73620 (patch) | |
tree | 062f8b5ab47ffdac84ee38adbdd21df14b5e6ab7 /input.c | |
parent | b7a23dec32a13984a7c1c68acfff70ae3d8ca4b2 (diff) |
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); |