what the the work of fflush(stdin) in c programming.am bits confused coz my programming is working same with it or without...
when you program , good approach is to cover all the possible situation/condition your program may encounter. in this case maybe you are lucky but suppose you make minor changes later on and then your program crashes , it`s bad. P.S : actually you will not encounter any problem if you input string/char once. E.g gets(string_name) ; // this will work fine //this will work for one iteration properly while(some condition) { gets(string_name); }
i feel maybe i was not able to explain so clearly, maybe someone can come up with a better explanation
You \(\bf{NEVER}\) use fflush(stdin) in C. This is an undefined call and how it works can change from system to system. http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1052863818&id=1043284351 It is far better to find an alternate method that works on all compilers.
why ? its perfectly working in "c"...
Did you read the FAQ on it? On that compiler it is working... what about another one? What about if you start working for a company that wants standards based code? The standard says that is undefined, so you could lose a job for doing it.
oh yes,i did n thnks 4 ur help and sorry for stupid question...;)
The only stupid question is the one you do not ask! If you don't know, you need to find out. Now you are better prepared than any computer student that never learns this is an undefined and irregular performing function call.
hey, i got problem in declaring "456.3342520324414" this value which is given as a input by the user....thanks..advance..
What are you declaring it as?
i wanna declare it as "unsigned long long float/double" in c
Well, many of those are integer data types. I must be some sort of float to take in the decimals. http://www.tutorialspoint.com/cprogramming/c_data_types.htm
So you need a long double or you need to do some other input handling. It might take a library if really long, accurate numbers are needed.
mine answer is giving me correct upto 4 decimal points bt what i wan is till 8 or 9 decimal point..
What you put up there is like 15 decimal places.
The Linux man (manual) pages are a great reference: http://www.linuxmanpages.com/man3/fflush.3.php subroutines: http://www.linuxmanpages.com/man3/ top level: http://www.linuxmanpages.com/
In that, the input is limited to 0.0 < R < 99.999. So do some tests on the input and if it is outside thar range, send an error to the user.
ya, i understood that,but the main problem is to store this value after "pow(r,n)",?
Well, pow works in doubles.
ya,power work in double bt the output doesnt give me the exact like in the example...
That sounds like an issue in formatting the output.
yes..it is..so got any idea...?
Have you looked up printf? http://www.cplusplus.com/reference/cstdio/printf/ Look at g and G. That might help.
its not giving the right input...lol...lossing patients
Input or output? Also, floating point has rounding errors.... Can't remember if those are hard set or machine based.
so, how should it be corrected,could nt sleep 4 dis problem 4rm last night ...lol
Hmmm.... only thing I can think of would be to use the fixed comand, which will leave the 0s, then convert it to a string and parse the string to strip the 0s. http://stackoverflow.com/questions/6010838/how-to-keep-doubles-from-converting-to-scientific-notation-when-using-and-string That would make it with the 0s.
@Elkanah : for the fflush part e.mccormick is right , try and avoid fflush because it`s compiler and OS dependent from my personal experience it works perfectly in windows(gcc/codeblock) but doen`t work in linux(Ubuntu/gcc) so i prefer to flush it myself while((c = getchar()) != '\n'); because in many cases it`s '\n' that causes problems
Join our real-time social learning platform and learn together with your friends!