Here is a stupid question

This is a discussion on Here is a stupid question within the C++ Programming forums, part of the General Programming Boards category; But I am looking to know if there is a code to use that tells me the length of an ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    34

    Here is a stupid question

    But I am looking to know if there is a code to use that tells me the length of an integer.

    For example, the number 1204 contains 4 digits. also if anybody ever did a bucket sort program, what is the best way to go about writing a function for it. Should I use call-by-value or reference?

    Thanks

    The Ski
    http://members.ebay.com/aboutme/the_ski/

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    22
    Hi,
    Here is a code to count the Number of Digits.

    By
    A.Sebasti..

    #include<iostream.h>
    int main()
    {
    int number,digitCnt=0;
    cout<<"Enter the Number: ";
    cin>>number;
    while(number)
    {
    number=number/10;
    digitCnt++;
    }
    cout<<digitCnt<<endl;
    }

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    34
    A.Sebasti,

    Thank you for code.

    Also anyone have any input on the bucket sort?
    http://members.ebay.com/aboutme/the_ski/

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,434

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    34

    Thumbs up

    Salem, Thanks!

    One quick question. What does this '->' comand do in the program?
    http://members.ebay.com/aboutme/the_ski/

  6. #6
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    -> is used to access a structure member through a pointer.

    pointer->func();

    roughly equivalent to....

    (*pointer).func();
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  7. #7
    Registered User
    Join Date
    Sep 2001
    Posts
    34
    Cool!!!! Learning about pointers right now, and I do not see how pointers are useful in Programming, but hay, those who created the language came up with it, so I shall learn it and use it.
    http://members.ebay.com/aboutme/the_ski/

  8. #8
    Registered User
    Join Date
    Sep 2001
    Posts
    34
    Man I am just adding on to this stupid question today. Here is one more question.

    Half way through my program, I am intializing a 2-D array. Now when I go to compile the program, it says "variable-sized object `num3' may not be initialized"

    What does this mean and how do I correct it?
    http://members.ebay.com/aboutme/the_ski/

  9. #9
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    without seeing some code....... PASS!
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  10. #10
    Registered User
    Join Date
    Sep 2001
    Posts
    34
    Already corrected the problem. Was going this way:

    int array2[a][b] = {0};

    supposedly I can not do that with my compiler.
    http://members.ebay.com/aboutme/the_ski/

  11. #11
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,434
    > int array2[a][b] = {0};
    if a and/or b are variables, then its not a standard feature, though some compilers do support it.

    Best to see one of the many 'how to dynamically allocate a 2D array' posts.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stupid Question Probably
    By Kyrin in forum C Programming
    Replies: 2
    Last Post: 05-07-2006, 12:51 AM
  2. Replies: 7
    Last Post: 11-03-2005, 11:17 PM
  3. Stupid Question
    By digdug4life in forum C++ Programming
    Replies: 22
    Last Post: 05-17-2005, 11:43 AM
  4. stupid, stupid question
    By xelitex in forum C++ Programming
    Replies: 5
    Last Post: 12-22-2004, 07:22 PM
  5. Stupid question: What does Debugger do?
    By napkin111 in forum C++ Programming
    Replies: 6
    Last Post: 05-02-2002, 10:00 PM

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