Very wierd compiling problem!


I’ve tried to make a very simple statment:

float test = 3.14;

            printf("%f", test);

it wont print anything… what seems to be the problem?


I don’t think the RC supports printf with a float modifier. Try %d with an integer value and see what happens.

So far as I can tell, with the C18 compiler we use,

  1. strings to be printf’d need a terminating \r


  1. %f is not supported.

It appears to be possible (at least for us) to have a printf without a terminating \r, as long as you get a \r in before the buffer is flushed. (presumably at the end of the loop)

try using an intereger instead of a float, or even a char which will do the same thing a float does. a printable float is not compatable with the Ccompilers.

2 things:

To be technical, your error (as you’ve explained it) is run-time, not compile-time error. A run-time error is something odd that happens during the execution of the code that you didn’t expect. It may be a crash or just may not print what you thought it would.

The other “thing” is this: when do you need to print out floats? I dunno, maybe you do need them. Important values like motors are unsigned chars, however. Most of what you’re working with is bits and chars. If you really need this to work, it’s worth your time; otherwise, there are probably 400 better things to do.

Best of luck with it…

Paul dennis

If you absolutely must print out a float,do this: print the integer part, then take the remaining decimal part, multiply by some power of ten (say, 1000) and print out this number after a decimal point.