Thread: Scanning any number of inputs without using arrays.

  1. #1
    Registered User
    Join Date
    Apr 2018
    Posts
    3

    Scanning any number of inputs without using arrays.

    Hi everyone, i need to scan multiple inputs at the same line and number of inputs is up to the user. I have searched a lot and tried everything but i was unable to do it. I think we can do it easily with arrays but i am not allowed to use arrays. Do you have any idea how to do that?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    So what's wrong with
    while ( scanf("%d",&myint) == 1 )
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Apr 2018
    Posts
    3
    Quote Originally Posted by Salem View Post
    So what's wrong with
    while ( scanf("%d",&myint) == 1 )

    Thank you very much! I think this is the way
    But how do i get out of the loop? If i put break; it only prints the first input, if i don't it asks me forever for input.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Do you have some number (like say -1) you type in to mark the end of the list?

    Typing in a letter (eg 'q') would also quit the loop.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Apr 2018
    Posts
    3
    Quote Originally Posted by Salem View Post
    Do you have some number (like say -1) you type in to mark the end of the list?

    Typing in a letter (eg 'q') would also quit the loop.
    No i had to use the Enter key. But i figured it out by using '\n' to break the loop. So it is all good now. Thank you very much for your help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Counting the number of inputs
    By skrowten_hermit in forum C Programming
    Replies: 5
    Last Post: 09-26-2012, 11:57 AM
  2. Reading an Unknown Number of Inputs
    By Aeias in forum C++ Programming
    Replies: 13
    Last Post: 02-25-2012, 08:27 AM
  3. scanning multiple inputs
    By casey123 in forum C Programming
    Replies: 2
    Last Post: 10-17-2011, 01:47 AM
  4. Scanning Arrays from a file
    By Hikaru90 in forum C Programming
    Replies: 1
    Last Post: 02-10-2010, 09:06 PM
  5. Searching and Scanning Arrays
    By apoc632 in forum C Programming
    Replies: 7
    Last Post: 11-28-2003, 03:28 PM

Tags for this Thread