add logic for invalid char
authorjaesick.shin <jaesick.shin@samsung.com>
Mon, 10 Oct 2016 00:45:40 +0000 (09:45 +0900)
committerUze Choi <uzchoi@samsung.com>
Tue, 11 Oct 2016 01:56:38 +0000 (01:56 +0000)
this patch include,
add logic for invalid char in notificationprovider example only.
sometimes, input variable has an incorrect value.

Change-Id: Id8fa6152a7a7f15ef5d54425daf896680d6c9447
Signed-off-by: jaesick.shin <jaesick.shin@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/12979
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/notification/examples/linux/notificationprovider.c

index 9ec10a5..c864669 100644 (file)
@@ -22,6 +22,7 @@
 #include <stdbool.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <ctype.h>
 
 #include "NSProviderInterface.h"
 #include "NSCommon.h"
@@ -193,15 +194,19 @@ int main()
 
         printf("input : ");
 
-        if(scanf("%d", &num) > 0)
+        if(scanf("%d", &num) > 0 && isdigit(num) == 0)
         {
-            fflush(stdin);
             if(scanf("%c", &dummy) > 0)
             {
                 fflush(stdin);
                 printf("\n");
             }
         }
+        else
+        {
+            printf("invalid input \n");
+            num = 0;
+        }
 
         switch (num)
         {