填空题
下列给定的程序中,fun函数的功能是:将p所指的字符串中每个单词的最后一个字母改成大写(这里的“单词”是指有空格隔开的字符串)。
例如,若输入:“I am a student to take the examination”,
则应输出:“I aM A studenT tO takE thE examinatioN”。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#include<ctype.h>
#include<stdio.h>
void fun(char*p)
{
int k=0;
for(;*p;p++)
if(k)
{
/**********found**********/
if(p=="")
{
k=0;
/**********found**********/
*p=toupper(*(p-1));
}
}
else
k=1;
}
void main()
{
char chrstr[64];
int d;
system("CLS");
printf("/nPlease enter an English sentence within 63 letters:");
gets(chrstr);
d=strlen(chrstr);
chrstr[d]="";
chrstr[d+1]=0;
printf("/nBefore changing:/n%s",chrstr);
fun(chrstr);
printf("/nAfter changing:/n%s",chrstr);
}