Counting integer digits

This is a discussion on Counting integer digits within the C Programming forums, part of the General Programming Boards category; Ok! Thanks! mw...

  1. #16
    Registered User
    Join Date
    May 2005
    Posts
    207
    Ok! Thanks!

    mw

  2. #17
    Registered User
    Join Date
    May 2005
    Posts
    28
    Quote Originally Posted by Lionmane
    So I have to convert the number to text in order to count the digits?

    mw
    No I showed you how to do it above, log10. As for the suggestion with sprintf into buf, that is great but you need to have buf be the right size. You could just have it be as many digits as the largest int, but then you constrain your solution to only working for ints. What if you wanted to do a long long? Or use a math lib that allowed arbitrarily large numbers? The problem there is either you have to make an enormous buffer to handle all the possibilities or you have to limit yourself to just a couple of possible data types.



    Mezzano

  3. #18
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  4. #19
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    An enormous buffer? Now you're just making ........ up.
    ULLONG_MAX
    Maximum value of type unsigned long long.
    Minimum Acceptable Value: 18446744073709551615
    Twenty one is "enormous"? Wow. What do you classify BUFSIZ as?
    Huge-enorm-gigan-super-behemothic-big-tastic?


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

  5. #20
    Registered User
    Join Date
    May 2005
    Posts
    28
    Quote Originally Posted by quzah
    An enormous buffer? Now you're just making ........ up.

    Twenty one is "enormous"? Wow. What do you classify BUFSIZ as?
    Huge-enorm-gigan-super-behemothic-big-tastic?


    Quzah.
    Either you can't read or you think arbitrarily large integer == unsigned long long. Sorry if I find your solution lacking, just stating my opinion, obviously you aren't very open to any ideas that aren't your own. I found your attitude quite prevalent among a number of people on this board, it is sad you view self-esteem, or self-worth or whatever you are seeking here as zero-sum, sad indeed. Don't worry I probably won't be frequenting this board anymore, in my short time here I have found a number of people that think they know everything. I prefer not to deal with people that can't take criticism of their ideas or alternative suggestions without crying. I am sure you will reply, you seem the type that must get in the last word no matter how banal it is, just know I won't be here to read it, but enjoy none the less.


    Mezzano

  6. #21
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by Mezzano
    Either you can't read or you think arbitrarily large integer == unsigned long long.
    Either you can't read, or you've forgotten what it is you actually said. Here, let me quote you:

    Quote Originally Posted by Mezzano
    No I showed you how to do it above, log10. As for the suggestion with sprintf into buf, that is great but you need to have buf be the right size. You could just have it be as many digits as the largest int, but then you constrain your solution to only working for ints. What if you wanted to do a long long? Or use a math lib that allowed arbitrarily large numbers?
    So you're telling me that log10 works for "a math lib that allowed arbitrarily large numbers"? Because apparently that's what your unfalable solution is. log10. No, really, go read what you actually wrote in this thread. The sum of your posts is: "log10 teh r0x0rz"

    Quote Originally Posted by Mezzano
    Sorry if I find your solution lacking, just stating my opinion, obviously you aren't very open to any ideas that aren't your own.
    That's funny, I was thinking the same thing about you.

    Quote Originally Posted by Mezzano
    I found your attitude quite prevalent among a number of people on this board, it is sad you view self-esteem, or self-worth or whatever you are seeking here as zero-sum, sad indeed. Don't worry I probably won't be frequenting this board anymore, in my short time here I have found a number of people that think they know everything. I prefer not to deal with people that can't take criticism of their ideas or alternative suggestions without crying. I am sure you will reply, you seem the type that must get in the last word no matter how banal it is, just know I won't be here to read it, but enjoy none the less.


    Mezzano
    Ah, gee that's too bad. I guess you can't handle being wrong. I seem to recall a thread where you were sure you were right and Salem was wrong, because he suggested a standard version of something you thought worked better with a non-standard function. I really do think you painted your self-portrait with that statement about you not being able to accept any one else's method for doing things.

    Anyway, don't let the door hit you in the ass on the way out.


    Quzah.
    Last edited by quzah; 05-24-2005 at 09:18 AM.
    Hope is the first step on the road to disappointment.

  7. #22
    SleepWalker tjohnsson's Avatar
    Join Date
    Apr 2004
    Posts
    70
    Code:
    int 
    calc_nums (int n) {
        return n ? calc_nums (n * 0.1F) + 1 : 0;
    }
    Here something...
    -- Add Your Signature Here --

  8. #23
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    That's a fun one. I think a lot of people miss the point here when they see another way of doing something. It seems a number of people think we're all "attacking them" just because we post a different way to do things. The reality is, and I can safely speak for many people here, we simply enjoy presenting "yet another way" to do any given task.

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

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-20-2009, 11:37 PM
  2. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 05:55 PM
  3. Assignment HELP!!
    By cprogrammer22 in forum C Programming
    Replies: 35
    Last Post: 01-24-2009, 01:24 PM
  4. Looking for constructive criticism
    By wd_kendrick in forum C Programming
    Replies: 16
    Last Post: 05-28-2008, 09:42 AM
  5. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 09:43 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21