/*读入一行英文文本,将其中每个单词的最后一个字母改成
大写,然后输出此文本行 (这里的“单词”是指由空格
隔开的字符串)。
例如:若输入“i am a student to take the examination.”,
则应输出“i aM A studenT tO takE thE examination.”*/
#include "conio.h"
#include <stdio.h>
#include "ctype.h"
#include "string.h"
void up1st ( char *p ) {
int k = 0;
for ( ; *p; p++ )
if ( k ) {
if ( *p == ' ' ) {
k = 0;
*(p - 1 ) = toupper( *( p - 1 ));
//toupper函数 把小写字母转换为大写字母
}
} else if ( *p != ' ' )
k = 1;
*( p - 1 ) = toupper( *(p - 1) );
}
int 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 );
return 0;
}
运行结果