![]() |
|
#1
|
|||
|
|||
Need Help Modifying CodeI need to modify this code so that if anything other than a digit is typed, the input is considered to be an error. I tried several codes, but I have not been successful. Can someone offer some help?
CPP / C++ / C Code:
Last edited by dsmith : 08-Nov-2004 at 06:26.
Reason: Please use [c] & [/c] for syntax highlighting
|
|
#2
|
||||
|
||||
|
Hi sosy2001. The code works fine for me, except in cases where a real value is entered. I added a strchr command to look for a decimal. I also added a semicolon after the while statement (necessary to compile) and put it into a small program. Works fine. The logic seems sound and it is pretty efficient.
CPP / C++ / C Code:
Cheers. __________________
The best damn Sports Blog period. |
|
#3
|
|||
|
|||
|
Quote:
Can you be a little more specific? For example, what if the user enters 123a Is this OK (with the integer value = 123, and everything else discarded)? Regards, Dave |
|
#4
|
||||
|
||||
|
Hi sosy2001. I am sorry! I didn't fully test that! I was so enamored with the logic that I overlooked full testing!!!!
Unfortunately, I couldn't figure out how to make it work the way you had it. There may be a much better solution than this, but this is what I came up with: CPP / C++ / C Code:
Again, I am sorry about that. It is easy to see how important thorough testing is ![]() __________________
The best damn Sports Blog period. |
|
#5
|
|||
|
|||
Need More HelpThis code did not work either. The main focus of this code is sscanf, and to print only integers or display the error message.
Sorry for being so complicated.And thanks for your assistance. |
|
#6
|
||||
|
||||
|
Hi sosy2001. Just curious, did the code not work or is it not acceptable because it does not use sscanf? I am certainly not above bad programs (I write them everyday
), but that code compiled and worked for every input that I threw at it.If it is that sscanf is required, I will take a look at that and see if I can think of a way to do that... __________________
The best damn Sports Blog period. |
|
#7
|
|||
|
|||
I got errorsI tried to use it but i got some error messages. I will foward these error messages to you in a few minutes.
Thanks. sosy2001 |
|
#8
|
|||
|
|||
Here Is the ErrorFirst the assignment question:
Examine the typical use of sscanf().Write a program that prompts the user to input a positive integer. Guard against errors so that a string typed by the user is picked up. CPP / C++ / C Code:
athus doesnot catch all the errors. For example 12X in typed instead of 123, the error is not caught. So I have to modify this code to fix this problem. |
|
#9
|
||||
|
||||
|
Quote:
Actually, you don't have an error as far as sscanf() is concerned. It converted what it could and stopped and the first non-digit character. I did some testing, and sscanf() will not see "23x" as an error because the '23' returns the value 1 and 'n' is 23. The 'x' is simply the character that determins the end of the number. You might try CPP / C++ / C Code:
Also, your statement CPP / C++ / C Code:
CPP / C++ / C Code:
__________________
Age is unimportant -- except in cheese |
|
#10
|
|||
|
|||
I have an error in my code I can't figure it outThis program is written in five different files. I keep getting an error message and I cant figure out what it means. Can you help me please. Here is the error message I get:
ay.obj : error LNK2001: unresolved external symbol _report_a_loss Debug/prn1.exe : fatal error LNK1120: 1 unresolved externals Error executing link.exe. prn1.exe - 2 error(s), 0 warning(s) -------------------------------------------------------------------------- CPP / C++ / C Code:
Last edited by dsmith : 17-Nov-2004 at 07:03.
Reason: Please use [c] & [/c] for syntax highlighting
|
Recent GIDBlog
More photos on Flickr by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Re: Formatting C / C++ code | WaltP | C Programming Language | 1 | 06-Jan-2008 23:59 |
| getting pWned by this code | quasimof | C++ Forum | 1 | 21-Oct-2004 22:30 |
| very difficult code - program | gaurav_sting | C++ Forum | 1 | 16-Jun-2004 00:59 |
| Explain code in MS STL's binary_search | rom | C++ Forum | 11 | 07-Mar-2004 20:11 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The