Thread: stoping inputs into an array

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    10

    stoping inputs into an array

    how would i read inputs into an array until the number 0 is imputed, which at that point continues to a sorting function. I have a sorting function written, i just don't know how to terminate the inputing.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    read a number
    if it's zero stop
    process
    go back to top of loop

  3. #3
    * noops's Avatar
    Join Date
    Jun 2008
    Posts
    108
    How are you getting input?

    If you are using getchar() in a while loop then you can use break to get out of the while loop if getchar() returns a 0.

    Code:
    while
    {
         /* stuff */
         if( something == 0 )
              break; /* exits the while loop */
    }

  4. #4
    Registered User
    Join Date
    Nov 2004
    Location
    USA
    Posts
    516
    If you are using getchar() in a while loop then you can use break to get out of the while loop if getchar() returns a 0.
    getchar() would return the ascii value of 0 if the user inputs 0. So the checking condition would be getchar()=='0'. Why would you want to use getchar() anyway? A simple scanf() would do.
    Code:
    do
    {
       scanf("%d",&n);
       if(n==0)break;
       do stuff;
    }while(1);
    sort the array;
    Code:
    >+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.[-]>++++++++[<++++>-] <.>+++++++++++[<++++++++>-]<-.--------.+++.------.--------.[-]>++++++++[<++++>- ]<+.[-]++++++++++.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help for my output array
    By qwertysingh in forum C Programming
    Replies: 1
    Last Post: 02-17-2009, 03:08 PM
  2. Replies: 7
    Last Post: 11-25-2008, 01:50 AM
  3. Template Array Class
    By hpy_gilmore8 in forum C++ Programming
    Replies: 15
    Last Post: 04-11-2004, 11:15 PM
  4. two dimensional dynamic array?
    By ichijoji in forum C++ Programming
    Replies: 6
    Last Post: 04-14-2003, 04:27 PM
  5. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM