문자 파싱하는 tip
글쓴이: 은빛연어 / 작성시간: 화, 2003/07/08 - 7:11오후
^^*
문자를 파싱하기 위해서 머리 굴려가면서 for문 돌려가면서 플레그 온오프시키야져.. 후아~~ 복잡하다.. ㅋㅋ
물론 복잡한 파싱을 할경우엔 파싱 함수를 만들어야겟찌만 얼마 길지 않는 경우에는 쉽게 처리할 수 있습니다.. ^^* 참고하세요~~
main() { char *temp0="abc : 123"; char *temp1="abc:123"; char *temp2="abc :123"; char *temp3="abc: 123"; char prebuf[16], value[16]; /*value의 결과가 동일합니다.*/ sscanf(temp0, "%[^:]:%s", prebuf, value); printf("[%s][%d]\n", prebuf, atoi(value)); sscanf(temp1, "%[^:]:%s", prebuf, value); printf("[%s][%d]\n", prebuf, atoi(value)); sscanf(temp2, "%[^:]:%s", prebuf, value); printf("[%s][%d]\n", prebuf, atoi(value)); sscanf(temp3, "%[^:]:%s", prebuf, value); printf("[%s][%d]\n", prebuf, atoi(value)); }
sscanf에는 이외에도 여러가지 기능들이 있습니다. 조사해 보세요~~ 재미있을꺼예요 ^^*
Forums:
참고로 scanf의 Format Specifier로 정규식을 쓰는[c
참고로 scanf의 Format Specifier로 정규식을 쓰는
sscanf(temp0, "%[^:]:%s", prebuf, value);
와 같은 문법은 ANSI C에는 없습니다.
다른 플랫폼에서는 사용할 수 없습니다. 대신 strtok를 써야겠지요.
음....
어떤게 정규식 인지요?
--
Life is short. damn short...
Re: 음....
%[^:]
부분입니다.Re: 음....
[^:], 이 부분이 정규식이라면, 한글자만 매칭이 되어야 할텐데 :(
정규식, regular expression이라는 단어를 함부로 쓰면 안되겠죠.
그냥 일정 패턴에 따라 받을 수 있다고 쓰는게 좋을 거 같습니다.
Re: 음....
"%[^:]:%s" 이거 이상하지 않나요?
There is no spoon. Neo from the Matrix 1999.
음... 궁금해 하시는 분들이 많이 있네요.. ^^cc나 gcc ma
음... 궁금해 하시는 분들이 많이 있네요.. ^^
cc나 gcc man-page를 보시면 답이 있습니다... 궁금해하시는분들 man-page에 주저리주저리 나와있는 영어를 먼저 분석하시길~~~ ^^*
참고로 컴터는 바봅니다.. 컴파일러에서 컴터가 아는것으로 바꿔주기전까진.. ^^+
(질문있으신분들~~ 부디 맨페이지부터 정독해주세요~~ ^^)
eungkyu I agree with your words.
eungkyu I agree with your words.
관련 없을 지도 모르지만msdn printf페이지의 문자열 포멧 관련
관련 없을 지도 모르지만
msdn printf페이지의 문자열 포멧 관련 링크에서도 자세히 나와있군요.
msdn 가지고 계신 분들은 확인해 보시길..
댓글 달기