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?

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.