title: Read from a text file and use each line to compare if they are anagrams
body: <p>I must modify my program to accept input from
  a file called anagrams.txt.This file should have two strings per line, separated by the # character. My program should read
  each pair of strings and report back if each pair of strings is an anagram. For example consider the following content of anagrams.txt:</p>
  
  <p><strong>hello#elloh<br>
  man#nam<br>
  Astro#Oastrrasd</strong></p>
  
  <p>Your program should print out the following:</p>
  
  <p><strong>hello#elloh - Anagrams!</strong></p>
  
  <p><strong>man#nam - Anagrams!</strong></p>
  
  <p><strong>Astro#Oastrrasd- Not anagrams!</strong></p>
  
  <p><strong>I should compile in g++</strong></p>
  
  <p>Here is the code to read from text:</p>
  
  <pre><code>int main()
  {
      char input[30];
  
  
  
  
        if(access( "anagrams.txt", F_OK ) != -1)           {
  
              FILE *ptr_file;
          char buf[1000];
  
          ptr_file =fopen("anagrams.txt","r");     if (!ptr_file)
              return 1;
  
          while (fgets(buf,1000, ptr_file)!=NULL)
              printf("%s",buf);
  
      fclose(ptr_file);
          printf("\n");
        }
  
        else{ //if file does not exist
          printf("\nFile not found!\n");
        }
  
  
          return 0;
  }
  </code></pre>
  
  <p>Code to find if the text are anagrams:</p>
  
  <pre><code> #include &lt;stdio.h&gt;
  
  int find_anagram(char [], char []);
  
  int main()
  {
      char array1[100], array2[100];
      int flag;
  
      printf("Enter the string\n");
      gets(array1);
      printf("Enter another string\n");
      gets(array2);
      flag = find_anagram(array1, array2);
      if (flag == 1)
          printf(" %s and %s are anagrams.\n", array1, array2);
      else
          printf("%s and %s are not anagrams.\n", array1, array2);
      return 0;
  }
  
  int find_anagram(char array1[], char array2[])
  {
      int num1[26] = {0}, num2[26] = {0}, i = 0;
  
      while (array1[i] != '\0')
      {
          num1[array1[i] - 'a']++;
          i++;
      }
      i = 0;
      while (array2[i] != '\0')
      {
          num2[array2[i] -'a']++;
          i++;
      }
      for (i = 0; i &lt; 26; i++)
      {
          if (num1[i] != num2[i])
              return 0;
      }
      return 1;
  }
  </code></pre>