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.
11 years, 4 months ago.
Scanf not working.. Help!
I tried to use scanf and it is not working at all.
- include "mbed.h"
- include<stdio.h> Serial pc(USBTX,USBRX); DigitalOut leds[]={(LED1),(LED2),(LED3),(LED4)}; void ledon(int no) { if(leds[no]==0) { leds[no]=1; } else { leds[no]=0; } }
int main() { int buffer=0; a: pc.printf("\nType numbers 1,2,3,4 to switch respective leds on and off\n"); pc.scanf("%d",&buffer); pc.printf("Its %d\n",buffer); switch(buffer) { case 1:ledon(buffer-1); break; case 2:ledon(buffer-1); break; case 3:ledon(buffer-1); break; case 4:ledon(buffer-1); } goto a; }
Is there a problem with the code?