Thread: Custom format specifiers ???

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    71

    Custom format specifiers ???

    Is it possible to make our own format specifiers ??

    data type can be redefined either using typedef or #define
    Code:
    #define LL long long
    typedef long long LL ;
    but what about this :
    Code:
    printf("%llu",var);
    is it possible to change %llu into something more general at the beginning itself ?

    Thank you

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    If you parse the string yourself, sure.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    If you want to add code to printf()'s header file (stdio.h), then sure. The source is right there.

    If your compiler supports a type long long integer, then your printf() should also support printing long long int's.

    The down and dirty method would be to just write a function to take your long long into a char array, and make the format changes you want to make, within that array, right inside your own function. Then you can print it just as you wanted it, as a string.

    Another way you can do work with very large int's is to have unsigned long's count up to the first million. That triggers the millions counter variable to increment by one, and resets the one's variable.

    You can repeat this for billions, trillions, and quadrillions, and go on as high as you need to. This is what I'm doing in a current search project for certain Sudoku grids. Every day the searcher finds, tests, and counts, about 20 billion puzzle grids. << cool! >>

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM
  2. wsprintf and format specifiers
    By incognito in forum Windows Programming
    Replies: 2
    Last Post: 01-03-2004, 10:00 PM
  3. header file bringing errors?
    By bluehead in forum Windows Programming
    Replies: 4
    Last Post: 08-19-2003, 12:51 PM
  4. gcc/borland and sscanf format specifiers
    By Sargnagel in forum C Programming
    Replies: 2
    Last Post: 01-24-2003, 06:40 PM
  5. Custom texture format?
    By Eber Kain in forum C++ Programming
    Replies: 1
    Last Post: 02-03-2002, 09:50 AM