Skip to content
Snippets Groups Projects
Commit 208fb845 authored by 20051799's avatar 20051799
Browse files

added todays assigment

parent 401bfcf4
No related branches found
No related tags found
No related merge requests found
.nfs*
aaaaaa
aaabca
#include <stdio.h>
#include <errno.h>
#include <string.h>
#define err(s) fprintf(stderr, s "%s\n", strerror(errno))
#define F1_STR "1.txt"
#define F2_STR "2.txt"
int main(void) {
int ret = 0;
FILE *f1;
if ((f1 = fopen(F1_STR, "r"))) {
FILE *f2;
if ((f2 = fopen(F2_STR, "r"))) {
char c1;
char c2;
int diff = 0;
while (fscanf(f1, "%c", &c1) != EOF &&
fscanf(f2, "%c", &c2) != EOF &&
!diff) {
if (c1 != c2) {
diff = 1;
printf("file 1: %c, file2: %c\n", c1, c2);
}
}
fclose(f2);
} else {
ret = 1;
err(F2_STR ": ");
}
fclose(f1);
} else {
ret = 1;
err(F1_STR ": ");
}
return ret;
}
abcdefghijk
abbdefgjklk
#include <stdio.h>
#include <errno.h>
#include <string.h>
#define err(s) fprintf(stderr, s "%s\n", strerror(errno))
#define F1_STR "1.txt"
#define F2_STR "2.txt"
#define FOUT_STR "out.txt"
int main(void) {
int ret = 0;
FILE *f1;
if ((f1 = fopen(F1_STR, "r"))) {
FILE *f2;
if ((f2 = fopen(F2_STR, "r"))) {
FILE *fout;
if ((fout = fopen(FOUT_STR, "w"))) {
char c1;
char c2;
while (fscanf(f1, "%c", &c1) != EOF &&
fscanf(f2, "%c", &c2) != EOF) {
if (c1 != c2) {
printf("file 1: %c, file2: %c\n", c1, c2);
fprintf(fout, "%c%c\n", c1, c2);
}
}
fclose(fout);
} else {
ret = 1;
err(FOUT_STR ": ");
}
fclose(f2);
} else {
ret = 1;
err(F2_STR ": ");
}
fclose(f1);
} else {
ret = 1;
err(F1_STR ": ");
}
return ret;
}
cb
hj
ik
jl
aaa bbb ccc ddd eee
aaa b ccc dd eeee
#include <stdio.h>
#include <errno.h>
#include <string.h>
#define err(s) fprintf(stderr, s "%s\n", strerror(errno))
#define F1_STR "1.txt"
#define F2_STR "2.txt"
int main(void) {
int ret = 0;
FILE *f1;
if ((f1 = fopen(F1_STR, "r"))) {
FILE *f2;
if ((f2 = fopen(F2_STR, "r"))) {
char s1[128];
char s2[128];
while (fscanf(f1, "%s", s1) != EOF &&
fscanf(f2, "%s", s2) != EOF) {
if (strcmp(s1, s2) != 0) {
puts(s2);
}
}
fclose(f2);
} else {
ret = 1;
err(F2_STR ": ");
}
fclose(f1);
} else {
ret = 1;
err(F1_STR ": ");
}
return ret;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment