I'm having some trouble with this member function of a class. Basically, it's meant to translate words to a different language while maintaining the same punctuation and spaces. lineToTranslate is an input argument which is an array of words, spaces and punctuation. Each word within this has to be taken out of the line individually and translated using the dict.translate() function. This is working properly.
However, the trouble is that when there is are multiple new lines, the previous line of words are output. Also whitespaces are not fully looked after. When there is more than one space in a sentence, only one space is output. Any idea's on where I might be going wrong? Any help would really be appreciated.
Updated code entered with most errors fixed. The only issue I'm having now is that spaces aren't added as needed between words. Where there are 2 blank spaces in a row, one blank space is being entered but where there is one blank space, none is being entered and the words areoutputlikethis.
int len = strlen(lineToTranslate);
string strComplete = "";
const char *cs;
for (int x = 0; x < len; x++)
{
if (!isspace(lineToTranslate[x]))
{
char temp[MAX_WORD_LEN];
int j = 0;
while(lineToTranslate[x] != ' ' && lineToTranslate[x] != '\t' && lineToTranslate[x] != '\n')
{
temp[j] = lineToTranslate[x];
x++;
j++;
}
temp[j] = '\0';
char returned[MAX_WORD_LEN];
if(temp[0] != '\0')
{
dict.translate(returned, temp);
strComplete = strComplete + returned;
}
}
else
{
strComplete = strComplete + lineToTranslate[x];
x++;
}
}
cs = strComplete.c_str();
strcpy(translatedLine, cs);