473,385 Members | 1,357 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

scanf doubt

6
float f;
scanf("%d",&f);
scanf("%f",&f);


first use of scanf is wrong but why didnt the second one work?? howdoes one wrong scanf affects all other later uses of scanf
Mar 29 '10 #1
3 1441
Banfa
9,065 Expert Mod 8TB
In what way did the second one not work?
Mar 29 '10 #2
donbock
2,426 Expert 2GB
@abhi17
In your first call to scanf you directed the function to overwrite a float variable with an int value. If sizeof(int) > sizeof(float) on your compiler then this action corrupted your program and you can't expect anything to work properly after that. On the other hand, I'm not aware of any compilers where sizeof(float) is less than sizeof(int).
Mar 29 '10 #3
donbock
2,426 Expert 2GB
@abhi17
Your first call to scanf you directed the function to overwrite a float variable with an int value. If sizeof(int) > sizeof(float) on your compiler then this action corrupted your program and you can't expect anything to work properly after that. On the other hand, I'm not aware of any compilers where sizeof(float) is less than sizeof(int); but that doesn't mean it can't happen.
Mar 29 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

21
by: clusardi2k | last post by:
/* The below code on SGI will wait for you to enter 2 things, but on Linux it will only wait the first time. I can make the code work by replacing the scanf with: char data ; fgets...
12
by: B Thomas | last post by:
Hi, I was reading O'Reilly's "Practical C programming" book and it warns against the use of scanf, suggesting to avoid using it completely . Instead it recomends to use using fgets and sscanf....
7
by: hugo27 | last post by:
obrhy8 June 18, 2004 Most compilers define EOF as -1. I'm just putting my toes in the water with a student's model named Miracle C. The ..h documentation of this compiler does state that when...
3
by: Vinicius | last post by:
Hello, the following code does not work: " .... void main(void) { char option; printf("Choose an option: ");
51
by: moosdau | last post by:
my code: do { printf("please input the dividend and the divisor.\n"); if(!scanf("%d%d",&dend,&dor)) { temp1=1; fflush(stdin); } else
185
by: Martin Jørgensen | last post by:
Hi, Consider: ------------ char stringinput ..bla. bla. bla. do {
25
by: Podrzut_z_Laweczki | last post by:
Hello, I have question (or 2 :)). Is that true that for a large data using scanf/printf instead of cin/cout makes that the program runs faster? And if it is, is it legal to mix scanf/printf with...
15
by: pereges | last post by:
have i written this program correctly ? it is giving me correct output but i am little suspicious in the following two statements - scanf("%d", &ptr->data) and printf("%d\n", ptr->data). ...
13
by: AMD | last post by:
Hello, I often need to parse strings which contain a mix of characters, integers and floats, the C-language scanf function is very practical for this purpose. I've been looking for such a...
51
by: deepak | last post by:
Hi, For the program pasted below, scanf is not waiting for the second user input. Can someone suggest reason for this? void main() { char c;
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.