找到你要的答案

Q:C - String errors

Q:字符串错误

I have a little problem with the strcat function in C. All I want is, take a string (org_surname), check that the character selected is a consonant and add it to another string(coded_surname).

int lenght = strlen(org_surname); int i = 0; int count = 0;

while(i<lenght && count < 3){
    if (org_surname[i] != 'a' && org_surname[i] != 'e' && org_surname[i] != 'i' && org_surname[i] != 'i' && org_surname[i] != 'u'){
        strcat(coded_surname,org_surname[i]);
        count++;
    }
    i++;
}

Errors is always the same.

 "passing argoment 2 of strcat makes a from integer without a cast.

How can I solve this problem?

我用strcat函数在所有我想要的是有一点小问题,需要一个字符串(org_surname),检查的特征选择是一个辅音,它添加到另一个字符串(coded_surname)。

int lenght = strlen(org_surname); int i = 0; int count = 0;

while(i<lenght && count < 3){
    if (org_surname[i] != 'a' && org_surname[i] != 'e' && org_surname[i] != 'i' && org_surname[i] != 'i' && org_surname[i] != 'u'){
        strcat(coded_surname,org_surname[i]);
        count++;
    }
    i++;
}

错误总是一样的。

 "passing argoment 2 of strcat makes a from integer without a cast.

我怎样才能解决这个问题?

answer1: 回答1:

The prototype of strcat() expects the second parameter to be const char * type but what you pass is char so there is an error.

You can check How to append a character to a string

对strcat()原型预计第二参数是const char*类型,但你过的字符,所以有错误。

您可以检查如何将字符追加到字符串中

answer2: 回答2:

Errors is always the same. "passing argoment 2 of strcat makes a from integer without a cast.

That's because you are passing org_surname[i] to strcat. The second argument to strcat needs to be a string, a char const*, not a char.

You can use:

len = strlen(coded_surname);
coded_surname[len] = org_surname[i];
coded_surname[len+1] = '\0';

错误总是一样的。 "passing argoment 2 of strcat makes a from integer without a cast.

那是因为你是通过org_surname [我]来将。为了将第二个参数必须是一个字符串,一个char const*类型,不是一个字符。

您可以使用:

len = strlen(coded_surname);
coded_surname[len] = org_surname[i];
coded_surname[len+1] = '\0';
c  string