![]() |
|
#1
|
|||
|
|||
Enter key in basic c programSorry if this question has been asked before but I couldnt find anything on it using google or the GID search.
Quick question that can probably be answered easily. I have a program that I'm doing for school and the only problem I'm having is with the Enter key. What I want to do is: using a loop, calculate the average number of a certain amount of numbers given by the user. All that is fine and working, but I'm also supposed to handle the situation if the user doesnt enter any numbers and just presses Enter. The program should then display "No input, quitting..." and then quit. I cant figure out what C recognizes as the enter key. Basicly I want something like this if (x == Enter Key) { printf ("No input, quitting"); delay (2000); exit (EXIT_SUCCESS); } Any help will be greatly appreciated. |
|
#2
|
|||
|
|||
|
Newline = 10 = 0xA.
|
|
#3
|
|||
|
|||
|
Quote:
I would probably use fgets() in a loop to read the entire line. If the only thing is a newline, then you know to quit. Otherwise, you get whatever information you expect to see on the line (combinations of strtok(), scanf(), strtol() or whatever you want.) CPP / C++ / C Code:
Regards, Dave |
Recent GIDBlog
Developing GUIs with wxPython (Part 4) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Airport Log program using 3D linked List : problem reading from file | batrsau | C Programming Language | 11 | 29-Feb-2008 07:44 |
| RSA program | fwongmc | C Programming Language | 11 | 08-Nov-2004 22:15 |
| C++ help | Grid | C++ Forum | 7 | 25-Oct-2004 22:40 |
| Anyone can write a program code for this??? | chriskan76 | C Programming Language | 1 | 19-Oct-2004 20:25 |
| Array..... | chriskan76 | C Programming Language | 4 | 18-Oct-2004 14:19 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The