summaryrefslogtreecommitdiff
path: root/input.c
diff options
context:
space:
mode:
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);