| Summary: | Error in the printf-function. | ||
|---|---|---|---|
| Product: | Base System | Reporter: | gh <gh> |
| Component: | misc | Assignee: | freebsd-bugs (Nobody) <bugs> |
| Status: | Closed FIXED | ||
| Severity: | Affects Only Me | ||
| Priority: | Normal | ||
| Version: | Unspecified | ||
| Hardware: | Any | ||
| OS: | Any | ||
On Sun, Mar 18, 2001 at 02:38:06PM -0800, gh@raditex.se wrote: > >Description: > The printf function seems to mix up whats a pointer and whats > a value... ? You must pass the correct types to printf if you want it to do something sensible. Each time you used "%f", which means "I am about to pass a float or a double", but you passed a mixture of other things. If you're a beginner C programmer then I'd suggest that you turn on some more compiler warnings, which will give about this: gcc -pedantic -ansi -W -Wall file.c Also, you might want to consult the C FAQ at: http://www.eskimo.com/~scs/C-faq/top.html and try reading the newsgroup comp.lang.c. David. State Changed From-To: open->closed Seems to be due to misues of printf. |
The printf function seems to mix up whats a pointer and whats a value... ? How-To-Repeat: Run this program #include <stdio.h> #include <stdlib.h> main() { int * Var; float Value; int IntVar; Value = 2.4; IntVar = 4; Var = malloc(4); *Var = Value ; /* Why is it like this? - explain */ if( 0 ) printf("Value is %f \n", Value ); printf(" Var is %f \n", Var ); if( 1 ) printf("Value is %f \n", Value ); printf(" Var is %f \n", Var ); *Var = IntVar; if( 1 ) printf("Value is %d \n", IntVar ); printf(" Var is %d \n", *Var ); }