Report
5 years, 11 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:

Comment on this question

1 Answer

5 years, 11 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?

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

posted by Parkavi Prabhaharan 28 Sep 2013

To post an answer, please log in.