| | |
[C] scanf
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jun 2004
Posts: 2,108
Reputation:
Solved Threads: 18
•
•
•
•
Originally Posted by WolfPack
How do you know that it is reading only 5? Are you using a debugger or using printf? If you are using printf maybe you are using a wrong format specifier.
I've used the following specifiers:
%f -- gives 5.000000
%.2g gives 5 ( g is the only one I know how to use to format decimal places)
Uhhh, why does C have to be a pain in the butthole?
•
•
Join Date: Jun 2004
Posts: 2,108
Reputation:
Solved Threads: 18
It's reading the 5.5, but for some reason it's being truncated in the conversion:
C Syntax (Toggle Plain Text)
int num; if (sscanf(text,"%d",&num) == 1 && num > 0)
•
•
•
•
Originally Posted by server_crash
It's reading the 5.5, but for some reason it's being truncated in the conversion:
C Syntax (Toggle Plain Text)
int num; if (sscanf(text,"%d",&num) == 1 && num > 0)
%d is the format specifier to read an integer. So it will read only the integer part of the contents in text. You have to use something like %f or %lf. I dont know what is standard specific ( I thought lf was the correct one for double, but someone said above that it was wrong, but my MSVC compiler only reads double for the %lf specifier) . I also saw some suggestions for a double in the above replies of this thread. you can lookup them. Note:
English is not my first language. I dont know if being suggested to be a masochist is offending so much. But I know that being called an ******* is. I think that type of language is uncalled for. Think twice before posting things like that.
バルサミコ酢やっぱいらへんで
•
•
Join Date: Jun 2004
Posts: 2,108
Reputation:
Solved Threads: 18
•
•
•
•
Originally Posted by WolfPack
But%dis the format specifier to read an integer. So it will read only the integer part of the contents intext. You have to use something like%for%lf. I dont know what is standard specific ( I thought lf was the correct one for double, but someone said above that it was wrong, but my MSVC compiler only reads double for the %lf specifier) . I also saw some suggestions for a double in the above replies of this thread. you can lookup them.
•
•
•
•
Note:
English is not my first language. I dont know if being suggested to be a masochist is offending so much. But I know that being called an ******* is. I think that type of language is uncalled for. Think twice before posting things like that.
•
•
Join Date: Jun 2004
Posts: 2,108
Reputation:
Solved Threads: 18
This seemed to work for me:
C Syntax (Toggle Plain Text)
float num; if (sscanf(text,"%f",&num) == 1 && num > 0)
•
•
•
•
Originally Posted by server_crash
Oh, believe me, I did. I thought it through really well. I could have filled up a whole page on what I really wanted to say to that....
btw, what are the specific reasons why you need to use miracle c dude?
Last edited by iamthwee; Jun 17th, 2006 at 11:58 am.
*Voted best profile in the world*
•
•
Join Date: Jun 2004
Posts: 2,108
Reputation:
Solved Threads: 18
•
•
•
•
Originally Posted by iamthwee
A- ha ha ha. What you say is pure gold server_crash. I'm adding to your rep.
•
•
•
•
btw, what are the specific reasons why you need to use miracle c dude?
Last edited by server_crash; Jun 17th, 2006 at 12:00 pm.
•
•
•
•
Originally Posted by server_crash
Why don't you head on over to dictionary.com and tell me which is worse, what he said, or what I said. I'm still fuming over that. I could have said a lot more but I had some self control.
•
•
•
•
Originally Posted by dictionary.com
# A willingness or tendency to subject oneself to unpleasant or trying experiences.
Edit:
•
•
•
•
Originally Posted by server_crash
Hey, ya know, what's wrong with a little excitement? I knew YOU would understand
Last edited by WolfPack; Jun 17th, 2006 at 12:06 pm.
バルサミコ酢やっぱいらへんで
•
•
•
•
Originally Posted by WolfPack
Okay. I did. I found what Salem would have meant.
This was what I thought Salem meant when I saw his reply at first. Is this so much agitating to you?
Edit:
Okay. All is cool. I consider the original intent of this thread achieved.
*Voted best profile in the world*
![]() |
Similar Threads
- Source code for printf, scanf, cin, cout? (C)
- Scanf Equivalent (Java)
- Scanf problem (C)
- scanf - compiles but causes error (C++)
Other Threads in the C Forum
- Previous Thread: help
- Next Thread: socket programming in C question
| Thread Tools | Search this Thread |
#include * api append array arrays bash binarysearch changingto char character cm copyanyfile copypdffile createcopyoffile createprocess() csyntax database directory dynamic execv feet fgets file floatingpointvalidation fork framework frequency function getlogicaldrivestrin givemetehcodez global grade gtkwinlinux histogram homework i/o ide include infiniteloop initialization input interest intmain() iso keyboard kilometer license linked linkedlist linux list looping loopinsideloop. lowest matrix meter microsoft mqqueue oddnumber odf open openwebfoundation overwrite pause pdf pointer pointers posix power process program programming pyramidusingturboccodes read recursion recv recvblocked reversing scheduling segmentationfault send single socket socketprogramming standard strchr string suggestions system test testautomation testing threads unix urboc user whythiscodecausesegmentationfault win32api windowsapi





