replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / resource / csdk / security / provisioning / sample / cloud / cloudWrapper.c
index f044be7..7702c3d 100644 (file)
@@ -67,12 +67,16 @@ static bool readOptional(const char* description)
     }
 
     printf("Do you want to Enter %s (y/n):\n", description);
-    char choice = 0;
+    char temp, choice = 0;
 
     while(1)
     {
-        scanf("%c", &choice);
-        skipSpecialCharacters();
+        for(int ret = 0; 1 != ret; )
+        {
+            ret = scanf("%c", &temp);
+            skipSpecialCharacters();
+        }
+        choice = temp;
 
         switch (choice)
         {
@@ -86,11 +90,24 @@ static bool readOptional(const char* description)
 
 void readString(char* item, int length, const char* description, const char* example)
 {
+    char *temp = (char*)OICCalloc(length, sizeof(char));
+    if (NULL == temp)
+    {
+        OIC_LOG(INFO, TAG, "temp is NULL");
+        return;
+    }
+
     printf("Enter %s (f.e. %s):\n", description, example);
     char template[8] = { 0 };
     snprintf(template, sizeof(template), "%%%ds", length - 1);
-    scanf(template, item);
-    skipSpecialCharacters();
+
+    for(int ret = 0; 1 != ret; )
+    {
+        ret = scanf(template, temp);
+        skipSpecialCharacters();
+    }
+    strncpy(item, temp, length);
+    OICFree(temp);
 }
 
 /**
@@ -111,9 +128,16 @@ static void readOptionalString(char* item, int length, const char* description,
 
 void readInteger(int* item, const char* description, const char* example)
 {
+    int temp;
+
     printf("Enter %s (f.e. %s):\n", description, example);
-    scanf("%d", item);
-    skipSpecialCharacters();
+
+    for(int ret = 0; 1 != ret; )
+    {
+        ret = scanf("%d", &temp);
+        skipSpecialCharacters();
+    }
+    *item = temp;
 }
 
 /**