![]() |
|
#1
|
|||
|
|||
Simple error that i cant find... irritating meok when q is used to quit it prints out the intialized values of the rest of the array to 0... i dont want it to print these... also when the tenth integer is entered and the program ends the last integer entered is not printed but is initialized to 0 instead... any suggestions?.. im just trying to familiariz myself witht this stuff.. and this is being difficult.
CPP / C++ / C Code:
|
|
#2
|
||||
|
||||
|
I'm not seeing where you have "q to quit" implemented in your code.
__________________
-Aaron |
|
#3
|
|||
|
|||
|
Don't know about 'q' for quit, but heres a problem:
Change CPP / C++ / C Code:
to CPP / C++ / C Code:
When you have problems like this, I suggest you put a printf() after the place where you obtain user input (to make sure the program sees what you think it out to see). For example CPP / C++ / C Code:
" printf() is your friend." Regards, Dave |
|
#4
|
|||
|
|||
|
Quote:
|
|
#5
|
|||
|
|||
|
Quote:
|
|
#6
|
|||
|
|||
|
Quote:
The program that you posted requires 10 entries then prints out 10 values. Your scanf() is expecting an integer. If the user enters anything that is not an integer, it goes back through the loop for a total of 10 times. Each time scanf() is still looking at the (non-integer) character in the input buffer, so doesn't store anything in the array. I guess that global variables are initialized to 0, so you see zeros in places for which you haven't given values. This shows why lots of people say that scanf() is not very good for user input. Dave Last edited by davekw7x : 30-Mar-2004 at 13:27.
|
|
#7
|
|||
|
|||
|
Quote:
|
|
#8
|
|||
|
|||
|
Quote:
Lots of people use fgets() to get a complete line into a buffer, then sscanf(), atoi() or lots of other possibilities (including roll-your-own tests) for extracting numbers, characters, etc. Dave |
|
#9
|
|||
|
|||
|
Quote:
|
Recent GIDBlog
US Elections and the ?Voter?s Responsibility? by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Where can I find web statistics script / software? | rhino1616 | Web Design Forum | 2 | 02-Jan-2004 21:31 |
| HELP!: find window width? Center a <div>? | Kingherc | Web Design Forum | 2 | 06-Jul-2003 06:25 |
| How Do i get php to find out the file type of a file for me? | viperman95833 | MySQL / PHP Forum | 2 | 08-Mar-2003 10:48 |
| How do I find the Unix log file route? | jrobbio | Web Hosting Forum | 4 | 04-Feb-2003 08:40 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The