Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
6 years, 1 month ago.
Can not use "scanf" to get input from host PC keyboard via USB communication?
Hi there,
I am using LPC4088 to get my keyboard input via USB serial communication from the host PC ? The commands (putc , getc, and printf) are working. However, scanf does not work. It displayed nothing after typing several numbers on the keyboard. The code is:
Serial pc(USBTX, USBRX); tx, rx
int main() { float input; pc.baud(115200);
while(1) {
pc.printf("Please type a value:\n"); pc.scanf("%f", input); pc.printf("The input value is: %f\n", input);
} }
1 Answer
6 years, 1 month ago.
1) to make code readable please use
<<code>> your code <</code>>
2) you are using scanf incorrectly, it takes a pointer to the variable, not the variable. Try
Serial pc(USBTX, USBRX); //tx, rx int main() { float input; pc.baud(115200); while(1) { pc.printf("Please type a value:\n"); pc.scanf("%f", &input); // & to pass a pointer to input pc.printf("The input value is: %f\n", input); } }