如何获得C风格字符串函数的工作?

问题描述:

我正在尝试使函数计算c元素字符串中的元音和辅音,并将字符串更改为大写。每当我运行函数时,它总是返回“0”。我能做些什么来解决这个问题?谢谢您的帮助。如何获得C风格字符串函数的工作?

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]); } 

} 
+0

欢迎来到StackOverflow!你的代码很长,请尝试制作一个[mcve]。你也可能对自己感兴趣[如何调试小程序](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/)。如果你自己确定了问题,你的问题更有可能产生很好的答案。另请参见[我如何提出一个好问题?](http://stackoverflow.com/help/how-to-ask)。 –

Count()没有返回0.您只是没有将其返回值用于打印。

而在UpperCase()LowerCase(),你应该的toupper()tolower()返回值分配回text[i]。也就是说,

text[i] = toupper(text[i]); 
+0

是的。为了做到这一点,传递参数不应该是恒定的。 –

元音和辅音永远是零,因为您是按值传递它们,因此它们的值不会改变,以解决这个问题,你应该通过引用传递等功能的原型将是

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) 

同样在函数定义中,您正在递减的值?他们应该增加。