中的每个单词的第一个字母转换为大写字母,并显示转换后的字符串,例如:I love you 执行后为I Love You,我写了这个程序老师运行不对,求大神帮忙看看
#include
using namespace std;
#include
void exchange(char *p);
int main()
{
char *str;
char sentence[100];
cout<<"请输入一句英文:";
cin.getline(sentence,100);
str=sentence;
exchange(str);
return 0;
}
void exchange(char *p)
{
int n=0;
int i;
i=strlen(p); //先测算出字符的长度
for(int j;j {
n=n+1;
if(n==1)
{
if(p[j]>=97&&p[j]<=122)p[j]-=32;
}
else if(p[j-1]==' '&&p[j]>=97&&p[j]<=122)p[j]-=32;
}
cout<<"\n转换后的句子为"<}
//#include "stdafx.h"//vc++6.0加上这一行.
#include
using namespace std;
int main(void){
char sentence[100];
cout << "Enter a sentence...\nsentence=";
cin.getline(sentence,100);
if(sentence[0]>='a' && sentence[0]<='z')
sentence[0]&=0xDF;
for(int i=1;sentence[i];i++)
if(isalpha(sentence[i]) && (sentence[i-1]==' ' || ispunct(sentence[i-1])))
sentence[i]&=0xDF;
cout << "The result is: " << sentence << endl;
return 0;
}