반응형

문자를 숫자로 변환

만약 "365" 라는 문자가 있을 경우 이것을 숫자로 변환 하려면

int n=0,i=0;

char num[4]="365", c; // num[0] == 3

num[3]='\0';

c = num[0];

do{

n = n*10 + c - '0';

c = num[++i];

}while( c >= '0' && c<='9' ) // c 가 0~ 9 사이의 숫자 안에 있다면

// 널문자를 만나면 바져나온다

결과 3 , 36 , 365


int 변수의 숫자를 한개씩 때오기

// 문자의 숫자가 증가할 수록 매칭 숫자도 증가한다

int inc=10;
int total = 123;
int result;
for(int i=0;i<3;++i){

result = total%10;
total/=10;

}

반응형

+ Recent posts