Convert received value as int to char type in C

Asked

Viewed 12,496 times

-3

I am doing a college job in which I have to convert a received value to char so that I can write it out in full for example. Help me create this function.

  • Shows us what you have tried (in code form) and where you have doubt..

1 answer

1

A character can only represent a number from 0 to 9. If you want to convert a number greater than 9 into a string see: Converting int to string

Case really wanted a whole like char, you can do it this way:

int main(int argc, char *argv[]) {
    int inteiro = 1;  
    char caractere = inteiro+'0';

    printf("%c",caractere);

    return 0;
}

inserir a descrição da imagem aqui

See more explanations: Converting int to char in C

Browser other questions tagged

You are not signed in. Login or sign up in order to post.