Skip to content
Snippets Groups Projects
Commit 4a75a26d authored by manfr689's avatar manfr689
Browse files

Sumission part 3

parent 9aff870b
No related branches found
No related tags found
No related merge requests found
...@@ -24,17 +24,24 @@ int main(int argc, char **argv) ...@@ -24,17 +24,24 @@ int main(int argc, char **argv)
char line[80]; char line[80];
// Fix num lines, num columns, strdup-1 // Fix num lines, num columns, strdup-1
FILE *fin = fopen("bible.txt", "r"); 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)) { while (!feof(fin)) {
getline(line, fin); getline(line, fin);
lines[cur] = (char*) malloc(strlen(line)); lines[cur] = (char*) malloc(strlen(line));
strcpy(lines[cur], line); strcpy(lines[cur], line);
cur++; cur++;
} }
fclose(fin); fclose(fin);
}
FILE *fout = fopen("copy.txt", "w"); FILE *fout = fopen("copy.txt", "w");
for (int i=0; i<cur; i++) { for (int i=0; i<cur; i++) {
fputs(lines[i], fout); fputs(lines[i], fout);
} }
fclose(fout); fclose(fout);
return 0; return 0;
} }
...@@ -4,6 +4,8 @@ in the blanks, but most parts of the code are very similar.""" ...@@ -4,6 +4,8 @@ in the blanks, but most parts of the code are very similar."""
for (name,op) in [(:add, :+), (:sub, :-), (:mul, :*)] for (name,op) in [(:add, :+), (:sub, :-), (:mul, :*)]
# Create a function that is named for example add and returns the # Create a function that is named for example add and returns the
# sum of its two arguments # sum of its two arguments
@eval Base.$name(x,y) = x + y
end end
@assert 3 == add(1, 2) @assert 3 == add(1, 2)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment