so here when i have \n in scanf its asking for two inputs instead of one , i wanted to ask why this was the case .SHouldnt \n just casue to move to the next line ,why is it asking for another input and then giving the result for just the first one?
so here when i have \n in scanf its asking for two inputs instead of one , i wanted to ask why this was the case .SHouldnt \n just casue to move to the next line ,why is it asking for another input and then giving the result for just the first one?
First, please post your code in Code Blocks here in this forum rather than a fuzzy image.
Remove the '\n' from the scanf().Code:#include <stdio.h> int main(void) { float f, c; scanf("%f", &f); c=(f-32)/1.8; printf("The temp in Celsius is %f\n", c); return 0; }
Use a normal temp in Fahrenheit, such as 68 degrees F!
Output:
Code:$ ./foo 68 The temp in Celsius is 20.000000
Read this:
A beginners' guide away from scanf()
Any whitespace (space, tab, newline, etc) in a scanf format string causes it to "eat" all whitespace at that point up until the next non-whitespace character. Therefore it is generally a mistake to put any kind of whitespace at the end of a scanf format string.
It's also important to know that most scanf format specifiers also skip whitespace before scanning the input value. The only specifiers that do not skip whitespace are %c, %[], and %n (although %n doesn't actually scan a value but instead yields the number of characters read up to that point).
All truths are half-truths. - A.N. Whitehead