C++ 如何让C风格的字符串函数工作?
我正在尝试创建一个函数,该函数计算c样式字符串中的元音和辅音,并将字符串更改为大写。每当我运行该函数时,它总是返回“0”。我能做些什么来解决这个问题?谢谢你的帮助C++ 如何让C风格的字符串函数工作?,c++,C++,我正在尝试创建一个函数,该函数计算c样式字符串中的元音和辅音,并将字符串更改为大写。每当我运行该函数时,它总是返回“0”。我能做些什么来解决这个问题?谢谢你的帮助 int Count(const char[], int counter){ counter= 0; for(int i = 0; line.length[]; i++){ if(line[i] == 'a' || line[i] == 'e' || line[i] == 'i' || line[i] ==
int Count(const char[], int counter){
counter= 0;
for(int i = 0; line.length[]; i++){
if(line[i] == 'a' || line[i] == 'e' || line[i] == 'i' || line[i] == 'o' || line[i] == 'u'){
--counter;
}
void upperCase(const char[]){
for(int i = 0; line.length[]; i++) {
toupper(line[i]); }
}
Count()
未返回0。您只是没有将其返回值用于打印
在UpperCase()
和LowerCase()
中,应该将toupper()
和tolower()
的返回值赋回到text[i]
中。就是
text[i] = toupper(text[i]);
Count()
未返回0。您只是没有将其返回值用于打印
在UpperCase()
和LowerCase()
中,应该将toupper()
和tolower()
的返回值赋回到text[i]
中。就是
text[i] = toupper(text[i]);
元音和辅音将始终为零,因为您通过值传递它们,因此它们的值不会更改以解决此问题。您应该通过引用传递它们,因此函数原型将为零
int Count(const char[], int&); //function heading int Count(const char text[], int& a)
int Count2(const char[], int&); //function heading int Count2(const char text[], int &b)
在函数定义中,是否也在递减值?它们应该递增。元音和辅音将始终为零,因为您是通过值传递它们,因此它们的值不会改变以解决此问题。您应该通过引用传递它们,因此函数原型将为零
int Count(const char[], int&); //function heading int Count(const char text[], int& a)
int Count2(const char[], int&); //function heading int Count2(const char text[], int &b)
在函数定义中,是否也在递减值?它们应该递增。欢迎使用StackOverflow!您的代码很长,请尝试生成一个。你也可能对你自己感兴趣。如果你自己解决问题,你的问题更有可能得到好的答案。另请参见。欢迎来到StackOverflow!您的代码很长,请尝试生成一个。你也可能对你自己感兴趣。如果你自己解决问题,你的问题更有可能得到好的答案。另见。为了做到这一点,传递参数不应该是常数。是的。为了做到这一点,传递参数不应该是常数。