[C] scanf

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Closed Thread

Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: [C] scanf

 
0
  #31
Jun 17th, 2006
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?
Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: [C] scanf

 
0
  #32
Jun 17th, 2006
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)
Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: [C] scanf

 
0
  #33
Jun 17th, 2006
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.
バルサミコ酢やっぱいらへんで
Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: [C] scanf

 
0
  #34
Jun 17th, 2006
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.

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.
Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: [C] scanf

 
0
  #35
Jun 17th, 2006
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....
Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: [C] scanf

 
0
  #36
Jun 17th, 2006
This seemed to work for me:

  1. float num;
  2. if (sscanf(text,"%f",&num) == 1 && num > 0)
Quick reply to this message  
Join Date: Aug 2005
Posts: 5,266
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: [C] scanf

 
0
  #37
Jun 17th, 2006
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.
*Voted best profile in the world*
Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: [C] scanf

 
1
  #38
Jun 17th, 2006
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:

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.
Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: [C] scanf

 
0
  #39
Jun 17th, 2006
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.
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:
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.
バルサミコ酢やっぱいらへんで
Quick reply to this message  
Join Date: Aug 2005
Posts: 5,266
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: [C] scanf

 
0
  #40
Jun 17th, 2006
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.
*Voted best profile in the world*
Quick reply to this message  
Closed Thread

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC