C언어

숫자에 3자리마다 콤마 찍기

고요한하늘... 2013. 9. 13. 16:37

https://groups.google.com/forum/#!original/comp.lang.c/qdkgBJCgX9s/HjIy-MURXxYJ 참고


char * add_comma( int digit, char * buf )

{

        char *ptr, *result;

        int dp, sign;

        result = buf;

        ptr = fcvt( digit, 0, &dp, &sign  );

        while (dp--){

                *buf++ = *ptr++;

                if (dp % 3 == 0)

                        *buf++ = dp ? ',' : ' ';

        }

        *buf = '\0';


        return result;

}



'C언어' 카테고리의 다른 글

GNU LIB 관련 링크  (0) 2014.01.28
LC_ALL=C  (0) 2013.11.13
프로그래밍 관련 사이트  (0) 2013.09.10
로컬 프로그램 멀티 쓰레드  (0) 2013.08.08
multi process read   (0) 2013.08.08