Home>
# include<stdio.h>
void main ()
{
  int a = 10;
  printf ("%. 2x", a);
}


The execution result is [0a].

Is there any way to store this [0a] in the array as a character?
I'd like to create a program that stores data in a two-dimensional array from"00 "to" quote "in the repeated statement.

c
  • Answer # 1

    char bff [10];
    sprintf (bff,"%. 2x" ;, a);

    and bff will contain a string

  • Answer # 2

    Easy,
    sprinf (str,"% 02x" ;, a);// char str [3];

    However, if 0-7F is fixed,
    char * hexStr [] = {"00" ;,"01" ;, ....}
    And the hand called hexStr [a]. (Uses memory, but it's definitely faster)

  • Answer # 3

    sprintfallows you to create achar with the same format asprintfcan be exported to an array (man).