943,836 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 9340
  • C RSS
You are currently viewing page 4 of this multi-page discussion thread; Jump to the first page
Jun 17th, 2006
0

Re: [C] scanf

Quote 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.
Because if I don't use that method and just print out some number it works.

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?
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Jun 17th, 2006
0

Re: [C] scanf

It's reading the 5.5, but for some reason it's being truncated in the conversion:

  1. int num;
  2. if (sscanf(text,"%d",&num) == 1 && num > 0)
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Jun 17th, 2006
0

Re: [C] scanf

Quote originally posted by server_crash ...
It's reading the 5.5, but for some reason it's being truncated in the conversion:

  1. int num;
  2. if (sscanf(text,"%d",&num) == 1 && num > 0)
But %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.
Moderator
Reputation Points: 572
Solved Threads: 115
Mentally Challenged Mod.
WolfPack is offline Offline
1,559 posts
since Jun 2005
Jun 17th, 2006
0

Re: [C] scanf

Quote originally posted by WolfPack ...
But %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.
Wow, that makes me feel dumb. For some reason I was thinking %d for for double. Although, I believe I have tried %f with double and it gave weird results.

Quote ...
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.
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.
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Jun 17th, 2006
0

Re: [C] scanf

Quote originally posted by WolfPack ...
Think twice before posting things like that.
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....
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Jun 17th, 2006
0

Re: [C] scanf

This seemed to work for me:

  1. float num;
  2. if (sscanf(text,"%f",&num) == 1 && num > 0)
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Jun 17th, 2006
0

Re: [C] scanf

Quote 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....
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 iamthwee; Jun 17th, 2006 at 11:58 am.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Jun 17th, 2006
1

Re: [C] scanf

Quote originally posted by iamthwee ...
A- ha ha ha. What you say is pure gold server_crash. I'm adding to your rep.
Hey, ya know, what's wrong with a little excitement? I knew YOU would understand:cheesy:

Quote ...
btw, what are the specific reasons why you need to use miracle c dude?
Personal reasons. I was testing something stupid, but I just dropped it. I like Dev C++ too much.
Last edited by server_crash; Jun 17th, 2006 at 12:00 pm.
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Jun 17th, 2006
0

Re: [C] scanf

Quote 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.
Okay. I did. I found what Salem would have meant.
Quote originally posted by dictionary.com ...
# A willingness or tendency to subject oneself to unpleasant or trying experiences.
This was what I thought Salem meant when I saw his reply at first. Is this so much agitating to you?
Edit:
Quote originally posted by server_crash ...
Hey, ya know, what's wrong with a little excitement? I knew YOU would understand
Okay. All is cool. I consider the original intent of this thread achieved.
Last edited by WolfPack; Jun 17th, 2006 at 12:06 pm.
Moderator
Reputation Points: 572
Solved Threads: 115
Mentally Challenged Mod.
WolfPack is offline Offline
1,559 posts
since Jun 2005
Jun 17th, 2006
0

Re: [C] scanf

Quote 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.
All that mod power has gone to your head wolfie.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
This thread is currently closed and is not accepting any new replies.
Previous Thread in C Forum Timeline: help
Next Thread in C Forum Timeline: socket programming in C question





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC