In the code below, when I try to output out_phrase_char, I get a message that says "The Debugger has exited due to signal 10 (SIGBUS).The Debugger has exited due to signal 10 (SIGBUS)." Please help me as soon as possible. This is due at 11:59pm.
// classes example
#include <iostream>
#include <cstdlib>
using namespace std;
class MyClass
{
public:
int *getNiCount(const char *phrase_char, const wchar_t *phrase_wchar) {
int index = 0;
int *num_occurences = new int[2];
while(phrase_char[index] != '\0') {
if(phrase_char[index] == 'N' && phrase_char[index+1] == 'i') {
num_occurences[0] = num_occurences[0] + 1;
}
index++;
}
index = 0;
while(phrase_wchar[index] != '\0') {
if(phrase_wchar[index] == 'N' && phrase_wchar[index+1] == 'i') {
num_occurences[1] = num_occurences[1] + 1;
}
index++;
}
return num_occurences;
}
char replaceNiWithNI(const char *phrase_char, const wchar_t *phrase_wchar) {
size_t temp;
char *out_phrase_char = (char*)phrase_char;
char *out_phrase_wchar;
temp = wcstombs(out_phrase_wchar, phrase_wchar, 14);
char *output_phrases = new char[2];
int index = 0;
while(phrase_char[index] != '\0') {
if(phrase_char[index] == 'N' && phrase_char[index+1] == 'i') {
out_phrase_char[index+1] = 'I';
}
index++;
}
index = 0;
while(phrase_wchar[index] != '\0') {
if(phrase_wchar[index] == 'N' && phrase_wchar[index+1] == 'i') {
out_phrase_wchar[index+1] = 'I';
}
index++;
}
//output_phrases[0] = out_phrase_char;
//output_phrases[1] = out_phrase_wchar;
return *out_phrase_char;
}
};
int main ()
{
MyClass phrase1;
const char *szTestString1 = "Ni nI NI nI Ni";
const wchar_t *szTestString2 = L"Ni nI NI nI Ni";
int *num_occurences = phrase1.getNiCount(szTestString1,szTestString2);
char out_phrase_char = phrase1.replaceNiWithNI(szTestString1,szTestString2);
cout << out_phrase_char << endl;
return 0;
}