Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How to store integer data (int type) in a string and then print this string with printf ()?
How to store integer data (int type) in a string and then print this string with printf ()?
Hello, the essence of this algorithm is type conversion, and we can use itoa function to realize it. The sample code is as follows:

//Copyright @ Quark

//Date: 20 10- 12-07

# include & ltstdio.h & gt

#define MAX_SIZE 100

# Define Data _ Count4

void main()

{

//Input data

int data[DATA_COUNT] ={ 1,23,456,7890 };

char shuju[MAX _ SIZE]= { 0 };

//Convert each plastic data into a string, and then copy it into the shuju array.

int index = 0;

char one data[20]= { 0 };

for(int I = 0; I & ltDATA _ COUNTi++)

{

Itoa (data [i], oneData,10);

char * temp = oneData

while (*temp! = '\0')

{

Shu ju[index++]= *(temp++);

}

}

//Print data

printf("%s ",shuju);

getchar();

}