每当我调用这个函数时,我的程序就会停止工作,但我似乎无法弄清楚为什么。这是我的代码片段:
#include <iostream>
#include <stdlib.h>
#include <string>
#include <fstream>
using namespace std;
void FindReplace(char Memory[], string FindWord, string ReplaceWord, const int MAXNUMCHARS)
{
int i = 0;
int SizeWord = FindWord.length();
int SizeReplace = ReplaceWord.length();
for(i = 0; i <= MAXNUMCHARS; i++)
{
if(Memory[i] == FindWord[i] && Memory[i+1] == FindWord[i+1] && Memory[i+2] == FindWord[i+2])
{
Memory[i] = ReplaceWord[i];
Memory[i+1] = ReplaceWord[i+1];
Memory[i+2] = ReplaceWord[i+2];
}
}
}
这是调用它的代码
if(option == 'F')
{
FindReplace(Memory, FindWord, ReplaceWord, MAXNUMCHARS);
OutputMemoryToFile(Memory , Out);//copies array to output file
cout << "String 'the' has been found and replaced with 'can'";
cout << endl;
}
请问有什么想法吗?:/