summaryrefslogtreecommitdiff
path: root/input.c
diff options
context:
space:
mode:
authorVincent Douillet <vincent@vdouillet.fr>2021-12-12 08:42:25 +0100
committerVincent Douillet <vincent@vdouillet.fr>2021-12-12 08:42:25 +0100
commit1c352d8c1dc97c8f6f11b7fbf38c621f53b73620 (patch)
tree062f8b5ab47ffdac84ee38adbdd21df14b5e6ab7 /input.c
parentb7a23dec32a13984a7c1c68acfff70ae3d8ca4b2 (diff)
Diffstat (limited to 'input.c')
-rw-r--r--input.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/input.c b/input.c
index 1c72194..02461a1 100644
--- a/input.c
+++ b/input.c
@@ -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);