Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdio.h"
- #include <stdlib.h>
- int main(int argc, char *argv[]) {
- if (argc < 4) {
- printf("Usage: %s file1.txt file2.txt output.txt\n", argv[0]);
- exit(1);
- }
- FILE *file1 = fopen(argv[1], "r");
- FILE *file2 = fopen(argv[2], "r");
- FILE *output = fopen(argv[3], "w");
- if (file1 == NULL||file2 == NULL||output == NULL) {
- printf("ERROR: Cannot open files\n");
- exit(1);
- }
- int file1Char;
- int file2Char;
- while ((file1Char = fgetc(file1)) != EOF && (file2Char = fgetc(file2)) != EOF) {
- if (file1Char == file2Char) {
- fputc(file1Char, output);
- } else {
- fputc(' ', output);
- }
- }
- fclose(file1);
- fclose(file2);
- fclose(output);
- }
Add Comment
Please, Sign In to add comment