home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 337.lha / same_v1.0 / same.c < prev    next >
C/C++ Source or Header  |  1990-01-28  |  1KB  |  72 lines

  1. #include <stdio.h>
  2. #include "string.h"
  3. #include "stdlib.h"
  4.  
  5. /* Same - Copyright (c) 1990 by Daniel Zenchelsky                        */
  6. /*                                                            */
  7. /*     Takes two sorted files and reports only those lines that match.        */
  8. /*     Case does not matter.                                        */
  9. /*                                                            */
  10.  
  11. extern char VersionString[];
  12.  
  13. char *upper();
  14.  
  15. main(argc,argv)
  16. int argc;
  17. char **argv;
  18. {
  19.     char data1[257],data2[257],udata1[257],udata2[257];
  20.     FILE *file1,*file2;
  21.     int cmp;
  22.  
  23.     printf("Same - Version 1.0 - %s\n",VersionString);
  24.     printf("Copyright (c) 1990 by Daniel Zenchelsky.\n\n");
  25.  
  26.     if (argc != 3)
  27.     {
  28.         printf("Usage: Same File1 File2\n");
  29.         exit(10);
  30.     }
  31.  
  32.     if ( (file1=fopen(argv[1],"r"))==NULL )
  33.     {
  34.         printf("Error opening file %s\n",argv[1]);
  35.         exit(10);
  36.     }
  37.     if ( (file2=fopen(argv[2],"r"))==NULL )
  38.     {
  39.         printf("Error opening file %s\n",argv[2]);
  40.         exit(10);
  41.     }
  42.  
  43.     fgets(data1,255,file1);
  44.     fgets(data2,255,file2);
  45.     
  46.     while (!feof(file1) && !feof(file2))
  47.     {
  48.         upper(data1,udata1);
  49.         upper(data2,udata2);
  50.  
  51.         cmp = strcmp(udata1,udata2);
  52.         if (cmp==0) printf("%s",data1);
  53.         if (cmp<=0) fgets(data1,255,file1);
  54.         if (cmp>=0) fgets(data2,255,file2);
  55.     }
  56.  
  57.     fclose(file1);
  58.     fclose(file2);
  59.  
  60. }
  61.  
  62. char *upper(in,out)
  63. char in[];
  64. char out[];
  65. {
  66.     int count;
  67.     for (count=0;in[count]!=NULL;count++)
  68.         out[count]=toupper(in[count]);
  69.     out[count]=NULL;
  70.     return(out);
  71. }
  72.