我在以句子大小写字符输出文本时遇到问题。当我提示:你好!你好。我还好。
我期待输出:你好!你好。我还好。
但我的示例运行输出是:你好!你好。我还好。
我的代码在 '!'/'.'/'?'/'_' 之后无法输出大写字母,谁能告诉我我犯了什么错误?提前致谢。
-艾莉
示例代码:
printf ("\n\nThe line of the text in sentence case is:\n");
i = 0;
text_ptr = text;
up = 1; /* up = 1 means upper case is yes */
while ( *(text_ptr+i) != '\0') /* could have been: while(text[i]) */
{
if(!up)
if( *(text_ptr+i-1)==' ' && toupper(*(text_ptr+i)=='I' && (*(text_ptr+i+1)==' ' ||
*(text_ptr+i+1)=='.' || *(text_ptr+i+1)=='!' || *(text_ptr+i+1))=='?') )
up = 1; /* capitalize i if all alone */
if(up)
if (*(text_ptr+i)!=' ' || *(text_ptr+i+1)=='.' || *(text_ptr+i+1)=='!' || *(text_ptr+i+1)=='?')
{
putchar(toupper(*(text_ptr++)));
up = 0;
} /* end if */
else
putchar(tolower(*(text_ptr++)));
else
{
putchar(tolower(*(text_ptr+i)));
if (*(text_ptr)=='?' || *(text_ptr)=='.' || *(text_ptr)=='!')
up = 1;
i++;
} /* end else */
}/* end while */`