From 4a75a26d8d533e43444e1ecae6617eea7e575123 Mon Sep 17 00:00:00 2001 From: manfr689 <manfr689@tlhw-4-3.ad.liu.se> Date: Tue, 8 Oct 2019 14:55:29 +0200 Subject: [PATCH] Sumission part 3 --- debugging/fileutil.cpp | 9 ++++++++- julia/run.jl | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/debugging/fileutil.cpp b/debugging/fileutil.cpp index f4dcc73..8bde202 100644 --- a/debugging/fileutil.cpp +++ b/debugging/fileutil.cpp @@ -24,17 +24,24 @@ int main(int argc, char **argv) char line[80]; // Fix num lines, num columns, strdup-1 FILE *fin = fopen("bible.txt", "r"); + //end-of-file condition is detected after trying read, not before. + //fopen passes a NULL. + if(fin){ while (!feof(fin)) { getline(line, fin); lines[cur] = (char*) malloc(strlen(line)); strcpy(lines[cur], line); cur++; } - fclose(fin); + fclose(fin); + } + FILE *fout = fopen("copy.txt", "w"); + for (int i=0; i<cur; i++) { fputs(lines[i], fout); } fclose(fout); + return 0; } diff --git a/julia/run.jl b/julia/run.jl index 3728a8f..f5fcfd8 100644 --- a/julia/run.jl +++ b/julia/run.jl @@ -4,6 +4,8 @@ in the blanks, but most parts of the code are very similar.""" for (name,op) in [(:add, :+), (:sub, :-), (:mul, :*)] # Create a function that is named for example add and returns the # sum of its two arguments + @eval Base.$name(x,y) = x + y + end @assert 3 == add(1, 2) -- GitLab