I'm needing to make a pig latin converter using only null terminated cstrings. I keep getting a segmentation fault error and can not figure out why. Also, only one word is being processed from the cin.get line when it needs to be the whole sentence. Anyone have any ideas?
#include <iostream>
#include <cctype>
#include <cstring>
using namespace std;
char converter(char *, char *);
int main ()
{
const int max = 50;
char *array;
char *arrtemp;
array = new char[max];
arrtemp = new char[max];
cout << "Enter a sentence you want converted to Pig Latin: \n";
cin.getline(array, max);
cout << endl;
while (loop)
{
if (array[j] == ' ')
{
j++;
}
for (int i = 0; array[j] != ' '; i++)
{
arrtemp[i] = array[j];
if (array[j] == '\0' || array[j] == '.')
{
continue;
}
j++;
}
first = arrtemp[0];
//To move first letter to end of word and ad 'ay' for words not starting with vowels
if (first != 'A' && first != 'a' && first != 'E' && first != 'e' && first != 'I' && first != 'i' && first != 'O' && first != 'o' && first != 'U' && first != 'u')
{
size = strlen(arrtemp);
I'm needing to make a pig latin converter using only null terminated cstrings.
One problems is that you aren't keeping the invariant for null terminated strings. (Yours aren't null terminated.) Feeding non-null terminated strings to strcat is a recipe for disaster.