We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hello to everyone, some incredibile detail about scanf (CARM)
unsigned char my_key; my_key=0; scanf("%c",&my_key);
When the PC sends a chr$(13) = CR the microcontroller receives a 0x0A = LF. I had my PC under suspicion to attach an additional LF. But now i'am using the int14h and controlled with an oszilloscope, there is no additional LF. So how to correct the scanf?
http://www.keil.com/support/man/docs/ca/ca_scanf.htm
http://www.keil.com/support/man/docs/ca/ca__getkey.htm
But, as already noted, why use scanf at all??
ok youre right, to receive just a single charakter _getkey() seems to be the right choice. But what function for receiving a manual typed float?
Andy told you to check _getkey() because scanf() calls _getkey() at the low level. Probably your _getkey() is translating CR to LF on-the-fly.
But, as already mentioned, why use scanf() at all?
If you are getting an ascii representation of a floating point value, it is relatively simple to transform the ascii stream into a float. For example, you can parse each char and add it to the current value of the conversion, previously multiplied by 10.
you can parse each char and add it to the current value of the conversion, previously multiplied by 10
Better use sscanf
Converting floating point from ascii to binary is too much work to just throw in any own code.
Most libraries contains atof() to make the conversion. This is most probably the function that is used internally by scanf(). It is part of both ANSI/ISO and Posix.