スペースの後に別のスペースがある場合など、文内にある余分なスペースをプログラムで削除することができません。また、ユーザーに続行を求めるために使用している while ループが、関数の実行を妨げています。削除すると、残りのプログラムが実行されます。
これが主な機能です:
int main()
{
bool program_start = 1;
char user_sentence[MAX];
cout<<"This program will take any sentence you write and correct any spacing\n"
<<" or capitalization (not proper nouns) mistakes you have.\n";
while(loop_continue(program_start))
{
input(user_sentence, MAX);
uppercase_spacing(user_sentence);
lowercase(user_sentence);
cout<<user_sentence;
}
return 0;
}
私の問題は uppercase_spacing 関数にあります。文内の余分なスペースを削除することはできません。
文を編集するために使用している void 関数は次のとおりです。
void uppercase_spacing(char sentence[])
{
int number = 0;
if(isspace(sentence[0]))
{
for(int i = 0; i < MAX; i++)
{
sentence[i] = sentence[i + 1];
}
while(number<MAX)
{
if((isspace(sentence[number])) && (isspace(sentence[number+1])))
{
sentence[number] = sentence[number + 1];
}
number++;
}
sentence[0] = toupper(sentence[0]);
}else{
for(int index = 0; index<MAX;index++)
{
if((isspace(sentence[index])) && (isspace(sentence[index+1])))
sentence[index]=sentence[index+1];
}
sentence[0] = toupper(sentence[0]);
}
return;
}
void lowercase(char sentence[])
{
for(int i = 1; (i < MAX) && (i != '\0'); i++)
{
sentence[i] = tolower(sentence[i]);
}
return;
}
私は他のすべてのプログラムでこのブール値を使用しているので、問題はプログラムの主要部分にあると思います。
while ループに使用しているブール関数は次のとおりです。
bool loop_continue(bool another_round)
{
bool again = another_round;
char continue_loop = 'y';
cout<<"Would you like to continue? Type y or Y for yes,\n"
>>" or any other letter for no.\n";
cin>> continue_loop;
if((continue_loop == 'y' )||(continue_loop == 'Y'))
{
cout<<"Okay, let's do this!"<<endl;
again = 1;
}else
{
cout<<"Goodbye."<<endl;
again = 0;
}
return again;
}
入力; 引用符はスペースの代わりになります。:
Candy CCandy " " " "something
出力; スペースはまだそこにあります:
キャンディ キャンディ " " " "何か