Search code examples
ccharacter-encoding

Simple int to char[] conversion


I have a simple question

How to simply convert integer (getting values 0-8) to char, e.g. char[2] in C?

Thanks


Solution

  • main()
    {
      int i = 247593;
      char str[10];
    
      sprintf(str, "%d", i);
    // Now str contains the integer as characters
    }
    

    Hope it will be helpful to you.