fill array with number

This is a discussion on fill array with number within the C Programming forums, part of the General Programming Boards category; Ok...I know I posted a similar question but since I never got an answer that was clear enough for a ...

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    42

    Unhappy fill array with number

    Ok...I know I posted a similar question but since I never got an answer that was clear enough for a noob like me, I'm begging you...tell me the code to read number (as char) in an array from my code. It's in the CheckNumber part. If you can modify this code so it work, I would greatly appreciate.

    Code:
    void CheckNumber(Number);
    int main(void)
    {     
         
         char Number[9];
    
         puts("Enter your numbers");
         gets(Number);
         CheckNumber(Number[]);
    
    /***************** CheckNumber *******************************/
    /************************************************************/
    void CheckNumber(Number[])
    {
    //from here, I don't know what to do so that it can work
    
    //Then I need to extract the numbers (char) form my array but this is not a problem
    thank you, hope this is not my last program
    Last edited by nevrax; 03-28-2007 at 02:39 PM.

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,159
    You didn't listen to anything anyone said in your previous thread, did you? And if you did, what exactly don't you understand from the advice given? Saying nothing was good enough, isn't good enough.

    Anyone that tries to help you at this point is just going to bang their head against the same brick wall trying to spoonfeed you information that you don't understand. And no one is just going to give you the code to answer your homework.
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    Mar 2007
    Posts
    42
    First, this is not my homework. Second, I'm glad to see that your truly great with the people who start, because I'm sure that you have always been an expert. This is a forum, if you don't want to answer, you don't have to.

  4. #4
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,159
    I gave you an answer. It's actually the 2nd post in your previous thread. And until you tell me what you don't understand about it, I can't help you anymore.
    If you understand what you're doing, you're not learning anything.

  5. #5
    Lean Mean Coding Machine KONI's Avatar
    Join Date
    Mar 2007
    Location
    Luxembourg, Europe
    Posts
    444
    First of all, I already pointed you to all the major FAQ entries for reading a number, so I won't bother to do that again.

    Second, your description of what you want to achieve is really vague, I honestly have no idea what you expect. If you read a number from the console into a string (like your code does), then you already have a number in an array.
    You have the following:

    char array[9];
    >> Please enter a number: 35523

    Then your array will look like this:
    ('3', '5', '5', '2', '3', '\0')

    As you can see, the "number" is in an array already, only that it's a char array and each digit inside the array represents the ASCII value of the number, not the number itself.

    What you want to do from here, is up to you, you can either convert it to a real number or whatever you feel like.

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,045
    Also as I'm sure someone mentioned (I didn't read the other thread), using gets() is an exceedingly bad idea. See the FAQ.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  7. #7
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Quote Originally Posted by dwks View Post
    (I didn't read the other thread)
    If you can find the time, at least skim it, it's highly entertaining.

  8. #8
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,045
    I see what you mean. put number in array

    Also:
    Code:
    CheckNumber(Number[]);
    You pass arrays with the name only, like so:
    Code:
    CheckNumber(Number);
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  9. #9
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    > see what you mean.
    It's hard to restrain oneself from commenting on it, but I think enough has been said.

    Anyway Nevrax, try what itsme86 and dwks have said, and use printf() and a for-loop to see if it worked. And post your code if you can't get it to work.

  10. #10
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,045
    Also look at this:
    Code:
    int convert_digit(char c) {
        return c - '0';
    }
    
    int x = convert_digit('4');
    /* x is 4 now, the number 4, not the character '4' */
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  2. convert 32 bit number to array of digits
    By droseman in forum C Programming
    Replies: 11
    Last Post: 02-18-2009, 08:37 AM
  3. Replies: 2
    Last Post: 02-08-2009, 08:26 PM
  4. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM
  5. Array Program
    By emmx in forum C Programming
    Replies: 3
    Last Post: 08-31-2003, 12:44 AM

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