Re: float

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



phoenixxz wrote:

> float i=1.34;
> printf("%f",i);
> 
> 
> ->> 0
> why?

You need to include <stdio.h> and write a main() function ;)

Beyond that: stdout will be line-buffered (if it's associated with a
terminal, block-buffered otherwise), so you should add a "\n" to the
end of the format string.

The lack of line buffering might have an effect if the program
terminates abnormally (exit() or returning from main() should cause
buffered streams to be flushed).

A working example:

	$ cat test.c
	#include <stdio.h>
	int main(void)
	{
	    float i=1.34;
	    printf("%f\n",i);
	    return 0;
	}
	$ gcc test.c
	$ ./a.out
	1.340000

-- 
Glynn Clements <glynn@xxxxxxxxxxxxxxxxxx>
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Assembler]     [Git]     [Kernel List]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [C Programming]     [Yosemite Campsites]     [Yosemite News]     [GCC Help]

  Powered by Linux