Advertisement
image28

just-bitwords.c

Aug 20th, 2019
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.78 KB | None | 0 0
  1. // Find words with a bit difference  ( I think thats what it was meant to do )
  2. // By image28 From 2004
  3. //
  4. // Compile with gcc filename.c -o executable-name
  5. // run with ./execuatable-name [wordlist file/dictionary 'words' file]
  6.  
  7. #include "defines.h"
  8. #include "strings.h"
  9.  
  10. int stringlen(char string[1000]);
  11. int stringcompare(char string[1000], char string2[1000]);
  12.  
  13. int main(int argc,char *argv[])
  14. {
  15.  
  16.     FILE *input;
  17.     FILE *output;
  18.     char out[1000];
  19.     long count=0;
  20.     int occurs=0;
  21.     int done=0;
  22.     int d=0;
  23.     int e=0;
  24.     char current_word[65535][100];
  25.     strcpy(out,argv[1]);
  26.     strcat(out,".out");
  27.  
  28.     if ( ( input=fopen(argv[1],"rb") ) == NULL ) exit(-1);
  29.     output=fopen(out,"wb");
  30.  
  31.     while ( ! feof(input) )
  32.     {
  33.         count=0;
  34.  
  35.         fscanf(input,"%s",current_word[0]);
  36.         printf("%s\n",current_word[0]);
  37.         do
  38.         {
  39.             count++;
  40.             fscanf(input,"%s",current_word[count]);
  41.             printf("%s %d\n",current_word[count], stringlen(current_word[count])); 
  42.    
  43.         }while ( ( stringcompare(current_word[0],current_word[count]) == 1 ) && ( ! feof(input) ) );
  44.         printf("COUNT %d\n",count);
  45.        
  46.         if ( count > 1 )
  47.         {          
  48.             for(d=0;d<count-1;d++)
  49.             {
  50.                 for(e=d+1;e<count;e++)
  51.                 {
  52.                     if ( stringcompare(current_word[d],current_word[e]) == 0 )
  53.                         occurs++;
  54.                 }
  55.  
  56.                 if ( ! occurs )
  57.                     fprintf(output,"%s\n",current_word[d]);
  58.             }
  59.        
  60.             fprintf(output,"\n");      
  61.         }      
  62.     }
  63.  
  64.     if ( count > 1 )
  65.     {
  66.         for(d=0;d<count;d++)
  67.             fprintf(output,"%s\n",current_word[d]);
  68.  
  69.         fprintf(output,"\n");      
  70.     }  
  71.  
  72.     fclose(input);
  73.     fclose(output);
  74.  
  75.     return(0);
  76. }
  77.  
  78. int stringlen(char string[1000])
  79. {
  80.     int count=0;
  81.        
  82.     while ( string[count] != '\0' )
  83.     {
  84.         count++;
  85.     }
  86.  
  87.     return(count);
  88. }
  89.  
  90. int stringcompare(char string[1000], char string2[1000])
  91. {
  92.     int count=0;
  93.     int d=0;
  94.  
  95.     for(d=0;d<stringlen(string);d++)
  96.     {
  97.         if ( string[d] != string2[d] )
  98.         {
  99.             count++;
  100.         }
  101.     }
  102.  
  103.     return(count);
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement