The program takes two txt files as arguments, the text file to be searched and the the text file containing the string to search for. We aren't allowed to use any string library functions. For some reason it works just fine on smaller text files for example:

textFileToSearch.txt:
this is fun
is this fun
fish
patternToSearchFor.txt:
is
returns:
Matches: 5
which is correct.

but if I use a much larger file like this:
Video provides a powerful way to help you prove your point.
When you click Online Video, you can paste in the embed code for the video you want to add.
You can also type a keyword to search online for the video that best fits your document.
To make your document look professionally produced,
Word provides header, footer, cover page, and text box
designs that complement each other.
For example, you can add a matching cover page,
header, and sidebar. Click Insert and then choose
the elements you want from the different galleries.
The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.The quick brown fox jumps over the lazy dog.


Video provides a powerful way to help you prove your point.
When you click Online Video, you can paste in the embed code for the video you want to add.
You can also type a keyword to search online for the video that best fits your document.
To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that comp$
more Great stuff
and search for
er
, it returns:
Matches: 62
when I'm pretty sure there are only 18 "er"s in that file.

I can't figure out why it doesn't work on bigger files. Any help would much appreciate.

(I know the Lines and Columns part isn't correct either, I'm more worried about the counting part right now)

Code:
#include<stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>

int patternFileLength(FILE *pattern){
  int len = 0;
  int chr;

  while((chr = fgetc(pattern)) != EOF){
    if(chr != '\0'){
      len++;
    }
  }
  return len;
}

int charcmp( char a, char b, int type ){
  if ( a == b ){
    type = 1;
    return 1;
  }
  else if(a == b || a - 32 == b || a + 32 == b){
    type = 2;
    return 1;
  }
  else if((a >= 48 && a <= 57) && (b >= 48 && b <= 57)){
    type = 3;
    return 1;
  }
  else{
    return 0;
  }
}

int main(int argc, char *argv[])
{
  FILE *textFile;
  FILE *patternFile;
  char x,y;
  int type = 0, match = 0, count = 0;
  int line = 1, col = -3;

  textFile = fopen(argv[1], "r");
  patternFile = fopen(argv[2], "r");

  int length = patternFileLength(patternFile);
  rewind(patternFile);

  y = fgetc(patternFile);

  while((x = fgetc(textFile)) != EOF){
    if(charcmp(x, y, type) == 1){
      y = fgetc(patternFile);
      match++;
      if(match == length){
        count++;
        match = 0;
        printf("LINE: %d    COL: %d\n", line, col);
      }
    }
    else{
      rewind(patternFile);
      y = fgetc(patternFile);
    }
    if(x == '\n' || x == '\0'){
      line++;
      col = -3;
    }
    col++;
  }

  printf("\nMatches: %d\n", count);

  fclose(textFile);
  fclose(patternFile);

  return 0;
}