6 years, 12 months ago.

Scanf not working.. Help!

I tried to use scanf and it is not working at all.

  1. include "mbed.h"
  2. 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?

Question relating to:

1 Answer

6 years, 12 months ago.

I tried your code and it works correctly on my mbed.

Can you specify your problem? What program do you use for communication?

Accepted Answer

I used teraterm... Reinstated it n now its okay... Thank u :)

posted by Parkavi Prabhaharan 28 Sep 2013