| | |
Please help me fix these errors
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
>I just need to ask you all to show me a bit more kindness so that I can get this thing working.
Kindness is not what you need nor will it get that thing working.
What you need is to understand how scanf() works.
scanf() always leave behind the ENTER key, when you press ENTER/RETURN. Which will be read by the next call.
If you insist in using it, then you need to accommodate that behavior.
A possible solution would be to declare another "waste key char" and using in conjunction with the first format , since you know you'll have to press enter to summit data.
Of course, that will not prevent the user from entering unexpected input and screwing it. That's for the best scenario.
Kindness is not what you need nor will it get that thing working.
What you need is to understand how scanf() works.
scanf() always leave behind the ENTER key, when you press ENTER/RETURN. Which will be read by the next call.
If you insist in using it, then you need to accommodate that behavior.
A possible solution would be to declare another "waste key char" and using in conjunction with the first format , since you know you'll have to press enter to summit data.
char enter_key;
scanf("%d%c", &num, &enter_key);•
•
Join Date: Dec 2008
Posts: 40
Reputation:
Solved Threads: 0
I don't insist upon using scanf. If you have a better suggest, then I am perfectly happy to hear it.
Trying you suggestion did cause each line to display. I was able to enter a number, a character, but not the floating point. When The line came up it already had a value there. The program also didn't assemlbe everything and print it as it's supposed to.
--
Okay, this time I tried it and the floating point line didn't have a value already. It, however, wouldn't let me type anything there.
Trying you suggestion did cause each line to display. I was able to enter a number, a character, but not the floating point. When The line came up it already had a value there. The program also didn't assemlbe everything and print it as it's supposed to.
--
Okay, this time I tried it and the floating point line didn't have a value already. It, however, wouldn't let me type anything there.
Last edited by RenFromPenn; Jan 4th, 2009 at 5:15 pm.
To start:
Read an Integer from the User, Part 1
Read an Integer from the User, Part 2
Read an Integer from the User, Part 3
Read a Floating-Point Value from the User, Part 1
Read a Floating-Point Value from the User, Part 2
Read a Floating-Point Value from the User, Part 3
Read a Line of Text from the User, Discard Excess Characters
Safe Version of gets()
Read an Integer from the User, Part 1
Read an Integer from the User, Part 2
Read an Integer from the User, Part 3
Read a Floating-Point Value from the User, Part 1
Read a Floating-Point Value from the User, Part 2
Read a Floating-Point Value from the User, Part 3
Read a Line of Text from the User, Discard Excess Characters
Safe Version of gets()
![]() |
Similar Threads
- class struct fix 2 new errors need advice (C++)
- Couple of errors in my code (Java)
- C Program help - Conway's Life - Stumped by some errors. (C)
- CHKDSK help - drive is dirty and I cannot fix any errors (Windows NT / 2000 / XP)
- errors in phpbb (PHP)
- CHKDSK hangs; won't fix HD errors--XP Pro (Storage)
- Errors with Linux file system (*nix Hardware Configuration)
- Random errors on new comp (Viruses, Spyware and other Nasties)
Other Threads in the C Forum
- Previous Thread: Need Help..!!
- Next Thread: any one have idea about compiler control directives
| Thread Tools | Search this Thread |
#include * append array arrays asterisks binarysearch calculate changingto char character cm copyimagefile cprogramme creafecopyofanytypeoffileinc database directory dynamic execv feet fgets file floatingpointvalidation fork forloop framework function getlogicaldrivestrin givemetehcodez grade gtkwinlinux hacking histogram ide inches include incrementoperators input intmain() iso kernel keyboard kilometer km license linked linkedlist linux list lists locate logical_drives looping loopinsideloop. lowest matrix microsoft mqqueue number oddnumber odf opendocumentformat opensource openwebfoundation overwrite owf pdf performance pointer posix probleminc process program programming radix recursion recv recvblocked research reversing scanf scripting segmentationfault sequential single socket socketprogramming standard string systemcall testing threads turboc unix urboc user variable wab whythiscodecausesegmentationfault windowsapi






