: .
{
if('\n' == sentence[i])
sentence[i] = ' ';
sentence[i] = tolower(sentence[i]); // change all character to lower
if( is_first_letter && isalpha(sentence[i]))
{
is_first_letter = false; // is_first_letter is TRUE, means the character is the first
// character of the line, so change it to upper.
sentence[i] = toupper(sentence[i]);
}
if(' ' == sentence[i] && !have_blank)
have_blank = true; // the present character is blank, the flag of charactor
is FALSE,
// that means the last character is not blank,
// then set the flag of charactor with TRUE.
else if(' ' == sentence[i] && have_blank)
i--; // the present character is blank, the flag of charactor is
TRUE,
// that means the last character is blank, and there are
multiple blanks
// so that must compresses multiple blanks to one
capitalizes,
// the index of char array must sub, fall back one
element
else if(' ' != sentence[i] && have_blank)
have_blank = false; // the present character is not blank, the flag of charactor
is TRUE,
// that means the last character is blank,
// then must change the status of the flag of charactor,
// set have_blank with FALSE, reset with initial status
Page 2 of 29 Copyright By Xu, CS, ScuecOOP 第三次实验答案
}
if(i < 99)
sentence[i+1] = '\0';
else
{
sentence[98] = '.';
sentence[99] = '\0';
}
size = i;
}
void get_sentence( char str[], int& size)
{
int i = 0;
char next;
(next);
while(next != '.' && i<100)
{
str[i] = next;
(next);
i++;
}
str[i]='.';
str[i+1]='\0';
size =
中南民族大学C++实验四参考程序 来自淘豆网www.taodocs.com转载请标明出处.