example of scanf & printf

Dependencies:   mbed

Fork of Serial_HelloWorld_Mbed by mbed official

Files at this revision

API Documentation at this revision

Comitter:
yokotay
Date:
Fri Jun 29 09:08:52 2018 +0000
Parent:
0:879aa9d0247b
Commit message:
example of scanf & printf

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 879aa9d0247b -r 5dda181255b2 main.cpp
--- a/main.cpp	Tue Feb 12 17:39:05 2013 +0000
+++ b/main.cpp	Fri Jun 29 09:08:52 2018 +0000
@@ -1,10 +1,15 @@
+/* an example for scanf() & printf() */
+
 #include "mbed.h"
  
 Serial pc(USBTX, USBRX); // tx, rx
  
 int main() {
-    pc.printf("Hello World!\n");
+    int num;
     while(1) {
-        pc.putc(pc.getc() + 1);
+        pc.printf("Input any integer number: ");
+        pc.scanf("%d", &num);
+        pc.printf("\r\nnum = %d\r\n", num);
+        pc.printf("num^2 = %d\r\n", num*num);
     }
 }
\ No newline at end of file
diff -r 879aa9d0247b -r 5dda181255b2 mbed.bld
--- a/mbed.bld	Tue Feb 12 17:39:05 2013 +0000
+++ b/mbed.bld	Fri Jun 29 09:08:52 2018 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/0954ebd79f59
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/a7c7b631e539
\ No newline at end of file