Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - C language string is converted into int array
C language string is converted into int array
The numeric characters in code://src are converted into numbers and stored in des.

//Returns the number of digits

int Change(int* des,const char* src)

{

int i,ret = 0,len = strlen(src);

for(I = 0; I & ltleni++)

{

if(' 0 ' & lt; = src[I]& amp; & amp9 ' >; = src[i])

{

des[ret++]= src[I]--0;

}

}

Return to ret

}void main()

{

Printf ("Please enter a string:");

char str[64]= { 0 };

gets(str); //Dynamically create an integer array to store the results.

int * ret =(int *)malloc(strlen(str)* sizeof(int));

int len = Change(ret,str); //Display the results

int I;

for(I = 0; I & ltleni++)

{

printf("%d\t ",ret[I]);

}

printf(" \ n "); //Free memory

Free (ret);

}