I'm writing a program that takes a file with the 3 lines of encrypted passwords and compares them to all 4 lower case letters from aaaa - zzzz. The only issue I am having is that I can't figure out how to go line by line of the file I input and how to compare it to the 4 letter words individually. It should then print the 3 decrypted 4 letter words that correlate to the passwords from the file. Also if there are any types on how to improve my code, please let me know. I'm a beginner at this so I need clear explanations and examples if possible. Thank you.
EDIT*****
The main problem is in the all function and main. I'm not wanting to print the aaaa, aaab, aaac, etc to the screen but I want to put it in an char array so that i can compare each individually to each line from the file using crypt. So I need advice on how to put all 456976 combinations into an array, compare it to each line of code, and print the solutions to the screen.
file looks like this:
$1$6gMKIopE$I.zkP2EvrXHDmApzYoV.B.
$1$pkMKIcvE$WQfqzTNmcQr7fqsNq7K2p0
$1$0lMKIuvE$7mOnlu6RZ/cUFRBidK7PK.
My code looks like this:
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define BUFFER_SIZE 1024
int my_fgets(char* buf, int len, int f)
{
   for (int i = 0; i < len; i++,buf++)
   {
      int count = read(f, buf, 1);
      if (!count || (buf[0] == '\n'))
      {
         buf[0] = 0;
         return i;
      }
   }
   return 0;
}
int inc(char *c,char begin, char end){
   if(c[0]==0) 
      return 0;
   if(c[0] == end){   // This make the algorithm to stop at char 'f'
      c[0]=begin;     // but you can put any other char            
      return inc(c+sizeof(char), begin, end);
   }   
   c[0]++;
   return 1;
}
char all(int a, int n,char begin, char end){
   int i, j;
   char *c = malloc((n+1)*sizeof(char));
   char result[] = "";
   for(i = a; i <= n; i++)
   {
      for(j=0;j<i;j++) c[j]=begin;
      c[i]=0;
      do {
         int k = sizeof(result);
         for (int g = 0; g < k -1; g++)
         {
            result[g] = c;
         }
      } while(inc(c,begin,end));
   }
   free(c);
}
int main(int argc, char* argv[])
{
   char *result;
   char let[456976];
   int f = open("pass.txt", O_RDONLY);
   if (f < 0) 
      return 0;
   char buf[1024];
   while (my_fgets(buf, sizeof(buf), f)) 
   {
      let = all(4,4,'a','z');
      int i = 0;
      result = crypt((let[i+1]), buf);
      int ok = strcmp (result, pass) == 0;
      return ok ? 0 : 1;
      all(4, 4, 'a', 'z');
   }
   close(f);
}
 
    