出力は入力と同じですが、どこで間違いを犯していますか? テスト バージョンを確認してください。「A」の ASCII コードが出力されますが、A は出力されません。なぜですか?
ループの最初の if 条件は、文字列がスペースではなく有効な文字のみで始まることを確認することです。
void caps(char* p)
{
char* begin=NULL;
char* temp=p;
while(*temp)
{
if((begin == NULL) && (*temp!= ' '))
begin=temp;
if(begin && ((*(temp+1) == ' ' ) || (*(temp+1)=='\0')))
{
toupper(*temp);
begin=NULL;
}
temp++;
}
cout<<p;
}
int main()
{
char str[]={"i like programming"};
cout<< str <<endl;
caps(str);
return 0;
}
テスト
printf("%c",toupper(a)) を使用すると、「A」が正しく出力されます。
#include <iostream>
#include <ctype.h>
using namespace std;
int main()
{
char a= 'a';
cout<<toupper(a); //prints ASCII code of A(65) but why not 'A' ?
return 0;
}