Hi i'm trying to write some functions for a version of Eliza and can't
seem to find way to reduce multiple instances of whitespace to a
single instance -
while((line[i] != '\0') || (line[i] != '.'))
{
/*This statement checks for two or more spaces together,
by comparing the current character with the previous one.
If found, i is incremented, thereby skipping the multiple spaces.
The result is then copied into 'cleaned'. */
if((line[i] == ' ' && line[i-1] == ' '))
{
i = i + 1;
}
cleaned[j] = line[i];
j = j + 1;
i = i + 1;
}
/*The 'cleaned' array, all lowercase and single spacing, is
copied
back into 'line' */
strcpy(line, cleaned);
}
I also tried -
if((line[i] == ' ' && line[i-1] == ' '))
{
i = i + 1;
}
line[j] = line[i];
j = j + 1;
i = i + 1;
}
both ways give me a 'segmentation error' when i try to run the program.
I'd really appreciate a nudge to point me in the right direction
thanks
Andrew