-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6169a2f
commit 841ad94
Showing
22 changed files
with
263 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
BINARY=fcompare | ||
|
||
include ../../Exercise.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# include <stdio.h> | ||
# include <stdlib.h> | ||
# include <string.h> | ||
|
||
/* file_open: open a file, and handle errors */ | ||
FILE *file_open (char *name, char *mode, char *prog) | ||
{ | ||
FILE *fp; | ||
if ((fp = fopen(name, mode)) == NULL) { | ||
fprintf(stderr, "%s ERROR! Can't open %s.\n", prog, name); | ||
exit(1); | ||
} | ||
return fp; | ||
} | ||
|
||
/* fgetline: read a line from a file, return length */ | ||
int fgetline (FILE *fp, char *line, int max) | ||
{ | ||
return | ||
fgets(line, max, fp) == NULL ? | ||
0 : strlen(line); | ||
} | ||
|
||
# define MAXLINE 1024 | ||
|
||
int main (int argc, char **argv) | ||
{ | ||
FILE *fp0, *fp1; | ||
char line0[MAXLINE], line1[MAXLINE]; | ||
int len0, len1, n; | ||
|
||
if (argc != 3) { | ||
printf("%s syntax: <file-a> <file-b>\n", argv[0]); | ||
return 0; | ||
} | ||
fp0 = file_open(argv[1], "r", argv[0]); | ||
fp1 = file_open(argv[2], "r", argv[0]); | ||
|
||
n = -1; | ||
do { | ||
n++; | ||
len0 = fgetline(fp0, line0, MAXLINE); | ||
len1 = fgetline(fp1, line1, MAXLINE); | ||
} while (len0 > 0 && len1 > 0 && len0 == len1 && strcmp(line0, line1) == 0); | ||
|
||
if (len0 != len1 || strcmp(line0, line1) != 0) | ||
printf("Files differ, line %d:\n" | ||
"%s: %s\n" | ||
"%s: %s\n", | ||
n, | ||
argv[1], len0 == 0 ? "[EOF]" : line0, | ||
argv[2], len1 == 0 ? "[EOF]" : line1); | ||
|
||
fclose(fp0); | ||
fclose(fp1); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0_file0.c 0_file1.c 0_file2.c |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
./fcompare syntax: <file-a> <file-b> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1_file0.c 1_file1.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
./fcompare ERROR! Can't open 1_file0.c. |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
main.c main.c |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
tests/3_file0.c tests/3_file1.c |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Files differ, line 25: | ||
tests/3_file0.c: int main (int argc, char **argv) | ||
|
||
tests/3_file1.c: int main (int argc, char **argv) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# include <stdio.h> | ||
# include <stdlib.h> | ||
# include <string.h> | ||
|
||
/* file_open: open a file, and handle errors */ | ||
FILE *file_open (char *name, char *mode, char *prog) | ||
{ | ||
FILE *fp; | ||
if ((fp = fopen(name, mode)) == NULL) { | ||
fprintf(stderr, "%s ERROR! Can't open %s.\n", prog, name); | ||
exit(1); | ||
} | ||
return fp; | ||
} | ||
|
||
/* fgetline: read a line from a file, return length */ | ||
int fgetline (FILE *fp, char *line, int max) | ||
{ | ||
return | ||
fgets(line, max, fp) == NULL ? | ||
0 : strlen(line); | ||
} | ||
|
||
# define MAXLINE 1024 | ||
|
||
int main (int argc, char **argv) | ||
{ | ||
FILE *fp0, *fp1; | ||
char line0[MAXLINE], line1[MAXLINE]; | ||
int len0, len1, n; | ||
|
||
if (argc != 3) { | ||
printf("%s syntax: <file-a> <file-b>\n", argv[0]); | ||
return 0; | ||
} | ||
fp0 = file_open(argv[1], "r", argv[0]); | ||
fp1 = file_open(argv[2], "r", argv[0]); | ||
|
||
n = -1; | ||
do { | ||
n++; | ||
len0 = fgetline(fp0, line0, MAXLINE); | ||
len1 = fgetline(fp1, line1, MAXLINE); | ||
} while (len0 > 0 && len1 > 0 && len0 == len1 && strcmp(line0, line1) == 0); | ||
|
||
if (len0 != len1 || strcmp(line0, line1) != 0) | ||
printf("Files differ, line %d:\n" | ||
"%s: %s\n" | ||
"%s: %s\n", | ||
n, | ||
argv[1], len0 == 0 ? "[EOF]" : line0, | ||
argv[2], len1 == 0 ? "[EOF]" : line1); | ||
|
||
fclose(fp0); | ||
fclose(fp1); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# include <stdio.h> | ||
# include <stdlib.h> | ||
# include <string.h> | ||
|
||
/* file_open: open a file, and handle errors */ | ||
FILE *file_open (char *name, char *mode, char *prog) | ||
{ | ||
FILE *fp; | ||
if ((fp = fopen(name, mode)) == NULL) { | ||
fprintf(stderr, "%s ERROR! Can't open %s.\n", prog, name); | ||
exit(1); | ||
} | ||
return fp; | ||
} | ||
|
||
/* fgetline: read a line from a file, return length */ | ||
int fgetline (FILE *fp, char *line, int max) | ||
{ | ||
return | ||
fgets(line, max, fp) == NULL ? | ||
0 : strlen(line); | ||
} | ||
|
||
# define MAXLINE 1024 | ||
|
||
int main (int argc, char **argv) | ||
{ | ||
FILE *fp0, *fp1; | ||
char line0[MAXLINE], line1[MAXLINE]; | ||
int len0, len1, n; | ||
|
||
if (argc != 3) { | ||
printf("%s syntax: <file-a> <file-b>\n", argv[0]); | ||
return 0; | ||
} | ||
fp0 = file_open(argv[1], "r", argv[0]); | ||
fp1 = file_open(argv[2], "r", argv[0]); | ||
|
||
n = -1; | ||
do { | ||
n++; | ||
len0 = fgetline(fp0, line0, MAXLINE); | ||
len1 = fgetline(fp1, line1, MAXLINE); | ||
} while (len0 > 0 && len1 > 0 && len0 == len1 && strcmp(line0, line1) == 0); | ||
|
||
if (len0 != len1 || strcmp(line0, line1) != 0) | ||
printf("Files differ, line %d:\n" | ||
"%s: %s\n" | ||
"%s: %s\n", | ||
n, | ||
argv[1], len0 == 0 ? "[EOF]" : line0, | ||
argv[2], len1 == 0 ? "[EOF]" : line1); | ||
|
||
fclose(fp0); | ||
fclose(fp1); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
tests/4_file0.c tests/4_file1.c |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Files differ, line 16: | ||
tests/4_file0.c: int fgetline (FILE *fp, char *line, int max) | ||
|
||
tests/4_file1.c: [EOF] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# include <stdio.h> | ||
# include <stdlib.h> | ||
# include <string.h> | ||
|
||
/* file_open: open a file, and handle errors */ | ||
FILE *file_open (char *name, char *mode, char *prog) | ||
{ | ||
FILE *fp; | ||
if ((fp = fopen(name, mode)) == NULL) { | ||
fprintf(stderr, "%s ERROR! Can't open %s.\n", prog, name); | ||
exit(1); | ||
} | ||
return fp; | ||
} | ||
|
||
/* fgetline: read a line from a file, return length */ | ||
int fgetline (FILE *fp, char *line, int max) | ||
{ | ||
return | ||
fgets(line, max, fp) == NULL ? | ||
0 : strlen(line); | ||
} | ||
|
||
# define MAXLINE 1024 | ||
|
||
int main (int argc, char **argv) | ||
{ | ||
FILE *fp0, *fp1; | ||
char line0[MAXLINE], line1[MAXLINE]; | ||
int len0, len1, n; | ||
|
||
if (argc != 3) { | ||
printf("%s syntax: <file-a> <file-b>\n", argv[0]); | ||
return 0; | ||
} | ||
fp0 = file_open(argv[1], "r", argv[0]); | ||
fp1 = file_open(argv[2], "r", argv[0]); | ||
|
||
n = -1; | ||
do { | ||
n++; | ||
len0 = fgetline(fp0, line0, MAXLINE); | ||
len1 = fgetline(fp1, line1, MAXLINE); | ||
} while (len0 > 0 && len1 > 0 && len0 == len1 && strcmp(line0, line1) == 0); | ||
|
||
if (len0 != len1 || strcmp(line0, line1) != 0) | ||
printf("Files differ, line %d:\n" | ||
"%s: %s\n" | ||
"%s: %s\n", | ||
n, | ||
argv[1], len0 == 0 ? "[EOF]" : line0, | ||
argv[2], len1 == 0 ? "[EOF]" : line1); | ||
|
||
fclose(fp0); | ||
fclose(fp1); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# include <stdio.h> | ||
# include <stdlib.h> | ||
# include <string.h> | ||
|
||
/* file_open: open a file, and handle errors */ | ||
FILE *file_open (char *name, char *mode, char *prog) | ||
{ | ||
FILE *fp; | ||
if ((fp = fopen(name, mode)) == NULL) { | ||
fprintf(stderr, "%s ERROR! Can't open %s.\n", prog, name); | ||
exit(1); | ||
} | ||
return fp; | ||
} | ||
|
||
/* fgetline: read a line from a file, return length */ |