資本化的第一個字,我需要作出這樣的大寫每個句子的第一個字符的字符串的程序。例如,如果字符串參數是「你好。我的名字是喬。你的名字是什麼?「該函數應該操縱字符串,使其包含」你好。我的名字是喬。你叫什麼名字?「我不確定我做錯了什麼。有什麼建議麼?這裏是我的代碼:每個句子
#include<iostream>
#include<cctype>
#include<cstdlib>
using namespace std;
void capitalize(char sentence[], int const SIZE);
int main()
{
const int SIZE = 1024;
char sentence[SIZE];
cout << "Enter a string: " << endl << endl;
cin.getline(sentence, SIZE);
capitalize(sentence, SIZE);
system("pause");
return(0);
}
void capitalize(char sentence[], int SIZE)
{
char *strPtr;
int count = 0;
sentence[0] = toupper(sentence[0]);
for (int i = 0; i < SIZE; i++)
{
strPtr = strstr(sentence[i], ".");
if (*strPtr == '.')
{
*strPtr = toupper(*strPtr);
}
}
while (sentence[count] != '\0')
{
cout << sentence[count];
count++;
}
}
什麼是你的代碼生成的輸出? – Fallen
@Fallen我收到一條錯誤消息,說'strstr'未在此範圍內聲明。 – PAXlater
一些提示:1)決定你是否正在編寫C或C++。 2)循環播放,直到達到SIZE最有可能超過用戶輸入的結尾。 –