Thread: Reading from User's Input

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    33

    Reading from User's Input

    Hi, I'm trying to read an unspecified number of integers from the user's input. However I don't know how to make it so that the program will keep on scanning after the first integer. I try to implement a loop but not sure on how to even begin.

    For example user's input:
    1 5 3 6 10
    The program will only read the "1" then stop, how do you make it so that it will read "1" "5" "3" "6" "10"?

    here is the code so far:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    int main(void)
    {
      int val;
    
      printf("Input Array Specification: ");
      scanf("&#37;d",&val);
      printf("val is: %d\n",val);
      return 0;
    
    }

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    What would you choose to break the loop?
    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.*

  3. #3
    Registered User
    Join Date
    Aug 2007
    Posts
    33
    I would like to break the loop when the last digit is detected.

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    How do you plan on distinguishing the "last" digit if there can be more?
    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.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading and processing input from keyboard
    By papagaio in forum C Programming
    Replies: 1
    Last Post: 11-12-2008, 03:59 PM
  2. reading input problems
    By gonzad in forum C Programming
    Replies: 1
    Last Post: 08-26-2008, 04:00 AM
  3. trouble reading input
    By panfilero in forum C Programming
    Replies: 3
    Last Post: 11-21-2005, 06:18 PM
  4. reading an input line using scanf() with %c
    By linucksrox in forum C Programming
    Replies: 6
    Last Post: 04-04-2004, 03:10 PM
  5. reading input files with different types of data
    By sanu in forum C++ Programming
    Replies: 4
    Last Post: 06-27-2002, 08:15 AM