2

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?

Arun A S
  • 6,421
  • 4
  • 29
  • 43

2 Answers2

4

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

Community
  • 1
  • 1
Gopi
  • 19,784
  • 4
  • 24
  • 36
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';
R Sahu
  • 204,454
  • 14
  • 159
  • 270