I have been working with a program and am almost finished. I am at the last few parts which of course are going to give me the most trouble.

In this part of the code, the user enters a name in which to edit. The name is located in a file. The program is supposed to search for the name, and then prompt the user to enter what the name should be changed to. But before it gets to that point, I get an illegal operation. That nice little message box that termates programs. I have been working on it for 2 days now, commenting and testing, but I am unable to find out specifically what line it is because it seems to move. Here is the source code for the functions:

Code:
void editfile()
 {
  system("cls");
  printf("Enter the name of the contact you wish to edit: ");
  cin.ignore(800, '\n');
  cin.getline(search, 256);
  strcat(fcontact, search);
  
  system("cls");
  printf(" *****************************************************************");
  printf("\n|          What do you want to do with this contact?              |");
  printf("\n|          1. Edit the contact's name                             |");
  printf("\n|          2. Edit the contact's phone number                     |");
  printf("\n|          3. Delete the contact                                  |");
  printf("\n *****************************************************************");
  printf("\nSelection: ");
  cin >> input;
  switch(input)
  {
   case 1: changename();
           break;
    
   case 2: changenumber();
           break;
   
   case 3: deletecontact();
           break;
   
   default: fileoptions();
            break;
  }         
 }     
 
 void changename()
 {
  fin.open(profilename); 
  while(!fin.eof())
  {
   i=0;
   fin.getline(szEdit[i], 256);
   i++;
   if (stricmp(fcontact, szEdit[i]) == 0)
   {
    fin.close();
    j = i;
    system("cls");
    printf("Contact found!");
    Sleep(1500);
    system("cls");
    printf("Enter the new name: ");
    
    // Does not seem to make it to this point.
    
    cin >> name;
    strcat(econtact, name);
    strcpy(name, econtact);
    strcpy(szEdit[j], name);
    fin.close();
    fin.open(profilename);
    while(!fin.eof()) 
    {
     i = 0;
     fin.getline(szEdit[i], 256);
     i++; 
    }
    k = i;
    strcpy(szEdit[j], name);
    fin.close();
    fout.open(profilename);
    while(i<=k)
    {
     i = 0;
     fout << szEdit[i];
     i++;
    }
    system("cls");
    printf("Editing complete!");
    fout.close();
    Sleep(1500);   
   }
  }  
 }
I made a little comment for the part the program cannot seem to get to. Thanks for all your help!