对于类,我需要编写一个从.txt文件获取输入的程序,使用c_strings将其转换为pig latin,然后将结果输出到另一个.txt文件。我已经测试了我自己的每个函数,并使用for()循环来迭代大约40个函数调用。当我通过大约60次调用但是我的调试断言失败了! popup陈述
“文件:minkernel \ crts \ ucrt \ inc \ corect_internal_string_templates.h
行:50
表达式:(L“缓冲区太小”&& 0)“
这是我对函数的调用。
while(!inputFile.eof())
{
engStr = readDataFromFile(inputFile);
pLatinStr = convertToPigLatin(engStr, pLatinStr);
outPutResults(outputFile, engStr, pLatinStr);
}
以下是被调用的函数。
char * readDataFromFile(ifstream &inFile)
{
char * arr = new char[20];
inFile.getline(arr, 15);
return arr;
delete[] arr;
}
bool checkVowel(char * engStr, int count)
{
if (
engStr[count] == 'a' ||
engStr[count] == 'e' ||
engStr[count] == 'i' ||
engStr[count] == 'o' ||
engStr[count] == 'u'
)
return true;
else
return false;
}
char * convertToPigLatin(char * engStr, char * pLatinStr)
{
char * arr = new char[20];
int count = 0;
pLatinStr = arr;
while (engStr[count] != '\0')
{
bool vowel = checkVowel(engStr, count);
if (vowel && count == 0)
{
stringCopyVowelFirst(pLatinStr, engStr);
break;
}
else
if (vowel)
{
stringCopyAfterVowel(pLatinStr, engStr, count);
break;
}
count++;
}
return pLatinStr;
delete[] arr;
}
void stringCopyAfterVowel(char *& pLatinStr, char * engStr, int count)
{
int LtnIndex = 0;
char ayStr[] = "ay\0";
char tempStr[20];
tempStr[0] = 0;
strcpy_s(pLatinStr, 15, engStr);
strncat_s(tempStr, strlen(tempStr) + 10, engStr, count);
while (engStr[count] != '\0')
{
pLatinStr[LtnIndex] = engStr[count];
count++;
LtnIndex++;
}
pLatinStr[LtnIndex] = '-';
pLatinStr[LtnIndex + 1] = '\0';
strcat_s(pLatinStr, 15, tempStr);
strcat_s(pLatinStr, 15, ayStr);
}
void stringCopyVowelFirst(char *& pLatinStr, char * engStr)
{
char wayStr[] = "-way\0";
strcpy_s(pLatinStr, 15, engStr);
strcat_s(pLatinStr, 15, wayStr);
}
void outPutResults(ofstream &outFile, char * engStr, char * pLatinStr)
{
outFile.open("pigLatinOut.txt", std::ofstream::app);
outFile << left << setw(12) << engStr << "\t";
outFile << setw(14) << pLatinStr << endl;
outFile.close();
}
非常感谢任何帮助。这是关于我学习c ++的第三周。