Guest User

Untitled

a guest
Oct 22nd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include "stdio.h"
  2. #include <stdlib.h>
  3.  
  4. int main(int argc, char *argv[]) {
  5. if (argc < 4) {
  6. printf("Usage: %s file1.txt file2.txt output.txt\n", argv[0]);
  7. exit(1);
  8. }
  9.  
  10. FILE *file1 = fopen(argv[1], "r");
  11. FILE *file2 = fopen(argv[2], "r");
  12. FILE *output = fopen(argv[3], "w");
  13. if (file1 == NULL||file2 == NULL||output == NULL) {
  14. printf("ERROR: Cannot open files\n");
  15. exit(1);
  16. }
  17.  
  18. int file1Char;
  19. int file2Char;
  20. while ((file1Char = fgetc(file1)) != EOF && (file2Char = fgetc(file2)) != EOF) {
  21. if (file1Char == file2Char) {
  22. fputc(file1Char, output);
  23. } else {
  24. fputc(' ', output);
  25. }
  26. }
  27.  
  28. fclose(file1);
  29. fclose(file2);
  30. fclose(output);
  31. }
Add Comment
Please, Sign In to add comment