카테고리 없음
[c언어] 오른쪽 끝에 있는 공백 삭제
xemaker
2017. 1. 3. 11:14
c언어 오른쪽 끝에 있는 공백을 삭제하는 함수이다.
사용법은 그냥 mys_rtrim(변수명);
void mys_rtrim(char *str){
char *pt;
int i;
for(istrlen(str)-1;i>=0;i--){
if(str[i]==0x20)
str[i]=0x00;
else
break;
}
}
예를들어 인포믹스 ec 환경인 경우
$char monthago[100];
memset(monthago,0x00,sizeof(monthago));
$select mdy(month(today,1,year(today)) -1 units month
into :monthago
from ppcommon:st203;
if(SQLCODE){
printf("error\n");
}
printf("monthago=[%s]\n",monthago);
//이렇게 하면 캐릭터 배열 100으로 해서 [2016-12-01
]
대충 이렇게 100자리 만큼 차지한다. 그래서 우측공백제거 함수를 써준다.
mys_rtrim(monthago);
이래서 다시 출력해본다.
printf("monthago=[%s]\n",monthago);
결과: [2016-12-01]
정상적으로 우측공백이 제거되었다.
사용법은 그냥 mys_rtrim(변수명);
void mys_rtrim(char *str){
char *pt;
int i;
for(istrlen(str)-1;i>=0;i--){
if(str[i]==0x20)
str[i]=0x00;
else
break;
}
}
예를들어 인포믹스 ec 환경인 경우
$char monthago[100];
memset(monthago,0x00,sizeof(monthago));
$select mdy(month(today,1,year(today)) -1 units month
into :monthago
from ppcommon:st203;
if(SQLCODE){
printf("error\n");
}
printf("monthago=[%s]\n",monthago);
//이렇게 하면 캐릭터 배열 100으로 해서 [2016-12-01
]
대충 이렇게 100자리 만큼 차지한다. 그래서 우측공백제거 함수를 써준다.
mys_rtrim(monthago);
이래서 다시 출력해본다.
printf("monthago=[%s]\n",monthago);
결과: [2016-12-01]
정상적으로 우측공백이 제거되었다.