Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How to convert characters into integer data I want in C language?
How to convert characters into integer data I want in C language?
# include & ltstdio.h & gt

# include & ltstdlib.h & gt

void main()

{

char fn[20]= " DDD 12345678 ffff ";

char tmp[20];

long num,i=0,j = 0;

while(fn[I]& lt; 0 ' | | fn[I]& gt; 9') // If it is not a number, go back.

i++;

while(fn[I]& gt; = ' 0 ' & amp& ampfn[I]& lt; ='9')// The found number is stored in tmp.

tmp[j++]= fn[i++];

tmp[j]= 0; //String terminator

num = atoi(tmp); //Convert the obtained string into an integer.

printf("%d\n ",num);

}