题目:读入一行英文文本,将其中每个单词的最后一个字母改成
大写,然后输出此文本行 (这里的“单词”是指由空格
隔开的字符串)。
例如:若输入“I am a student to take the examination.”,
则应输出“I aM A studenT tO takE thE examination.”。
解答:
#include <stdio.h>
#include <ctype.h>
#include <string.h>
up1st(char *p)
{
int k=0;
for ( ;*p; p++)
if(k)
{
if(*p==' ')
{
k=0;
*(p-1)=toupper(*(p-1));
}
}
else if(*p!=' ')
k=1;
}
main( )
{
char chrstr[81];
printf("\nPlease enter a string: " );
gets(chrstr);
printf("\n\nBefore changing:\n %s",chrstr);
up1st(chrstr);
printf( "\nAfter changing:\n %s", chrstr );
}