Does anyone know why my code has an error of "stack smashing detected"? And how I would go about fixing it? Thanks

Code:

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

int main(void) {
   
   char abc[26];
   FILE* encryptFile;
   char code[1000];
   int form = 0;
   char ch;
   
   encryptFile = fopen("encrypted.txt", "r");
   do {
      ch = fgetc(encryptFile);
      code[form] = ch;
      form+=1;
   }
   while (ch != EOF);
   fclose(encryptFile);
   encryptFile = fopen("substitution.txt", "r");
   
   for(int i=0;i<26;i++){
      char ch = fgetc(encryptFile);
      abc[ch-97]=(char)(i+97);
   }
   
   fclose(encryptFile);
   encryptFile = fopen("decrypted.txt", "w");
   char first[form];
   for(int i=0; i<form-1;i++){
      ch = code[i];
      if(ch >= 97 && ch <= 122)
      first[i]=abc[ch-97];
      else if(ch >= 65 && ch <= 90){
         first[i]=toupper(abc[tolower(ch)-97]);
      }
      
      else 
      first[i]=ch;
      fprintf(encryptFile, "%c",first[i]);
   }
      
 
   return 0;
}