Comparing and replacing accented/special characters in C

Viewed 124

So I have this example string in C which contains the following:

char text_string[100] = "A panqueca americana é provavelmente o caféç da manhã mais famoso dos Estados Unidos.";

I need to find and replace special characters such as "ç" and turn them into their non-accent counterpart (for instance, "ç" would become "c").

I'm really struggling with this, searched around but couldn't find anything to help with this question. I tried usint strchr to compare the individual chars of the text to the special characters like I'll show below but it didn't work.

char transform_text(char *text_string){
    for(int i=0; i<100; i++){
        if(strchr("ç", text_string[i]) != NULL )
            text_string[i]='c';
}

Any suggestions? Thank you in advance.

1 Answers

On OP's system, "ç" is length 3, (e.g. '0xc3', '0xa7', '0x00') thus it is not encoded as a single character.

A common encoding is UTF8: U+00E7 ç c3 a7 LATIN SMALL LETTER C WITH CEDILLA

Instead look for the string "ç" inside text_string and substitute with the shorter string "c".

Related