473,320 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to identify the end of input?

Problem Definition:
rewrite small numbers from input to output. Stop processing input after reading in the number 42. All numbers at input are integers of one or two digits.
Example
Input:
1
2
88
42
99

Output:
1
2
88

My code:
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. void main()
  3. {
  4. int nomore,i,j,output[100],number;
  5. nomore=5;
  6. i=0;
  7. while(scanf("%d",&number))
  8. {
  9. if(number==42)
  10. {
  11. nomore=0;
  12. }
  13. if(nomore!=0)
  14. {
  15. output[i]=number;
  16. i++;
  17. }
  18. }
  19. for(j=0;j<i;j++)
  20. {
  21. printf("%d\n",output[j]);
  22. }
  23. }
here the while loop is not breaking. So, how will i come to know that the input is over?
Feb 17 '12 #1
3 2266
Banfa
9,065 Expert Mod 8TB
Because you never break out of it and you don't have a condition in the while that would cause it to break either.
Feb 17 '12 #2
weaknessforcats
9,208 Expert Mod 8TB
Generally, you can't tell when the end of input occurs since more old be coming as soon as the user gets back from a coffee break. So you kind of wait forever.

The user will have to close the iput stream by signalling end-of-all-input. For console applications, this is usually CTRL+Z and this will show up in your program as EOF.
Feb 17 '12 #3
donbock
2,426 Expert 2GB
It is up to you to specify how you want the user to tell the program that input is complete. Here are some possibilities, but it is really up to you to decide what makes the most sense for how your program is used.
  1. Ask the user to tell you how many input values there will be before any of those values are entered.
  2. Explicitly ask the user to tell you if there is more input after each value is entered.
  3. Use CTRL-Z (ASCII EOF) to signal that input is complete. (Not all C implementations use ASCII.)
  4. A specific kind of illegal value implicitly indicates that there is no more input.
  5. Your program could be hard-coded to only accept precisely N input values.
  6. Something else that you think of.
Feb 17 '12 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: DraguVaso | last post by:
Hi, I want my application do different actions depending on the exception it gets. For exemple: I have an SQL-table with a unique index. In case I try to Insert a record that's alreaddy in it I...
4
by: multimatum2 | last post by:
Hello, I need to enable/disable input text forms... But... I need to have the same style (color...) in both modes.. Could you help me ? Thanx a lot A small sample... ...
5
by: BlackFireNova | last post by:
I need to write a report in which one part shows a count of how many total records fall within the working days (Monday - Friday) inside of a (prompted) given date range, in a particular...
7
by: Don Riesbeck Jr. | last post by:
I'm working on an application (OEM) using C# that utilizes input from a keyboard, and USB Barcode Scanner. The scanner is a HID Keyboard device, and input from it is sent to the system as if it...
1
by: Louis Cypher | last post by:
I'm working on an application (OEM) using c# that uses input from a keyboard and a USB Barcode Scanner. I need to be able to identify keystrokes from the barcode scanner and remove them from the...
1
by: hdogg | last post by:
So, this autosum works perfect but... since i'm dyamically going to submit multiple records... all of the form names will be the same ..." forecast" but when i try to sum all the fields that the...
7
by: Roy | last post by:
Hi , I use a A2003 App.I get a text file everyday from a external source which I use to update my tables.The problem is there is no consistent delimiter used in this text file.Some days it is...
2
by: xoinki | last post by:
hi all, I am just trying to identify which radio button is selected in JS. although the code in totality does not make any sense since this is just a sample. it is not able to identify the 's' name...
9
by: dudelideisann | last post by:
Hi! I have a form where the user enters some input. The input will eventionally become a database table. When he hit the 'submit' button the info is put into an array and then into a session...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.