无法检查给定数字是否为整数。 (使用scanf返回值)

时间:2017-02-14 05:06:46

标签: c integer scanf

int getvalue(int *arr_value, int number)
{
    int i = 0;
    int temp =0;
    while(i < number)
    {
        if((scanf("%d",temp)) == 1) // to check whether input is integer 
        {
            arr_value[i++] = temp; // to store it in array only if it is int
        }
        else
        {   
            printf("\n Enter a proper integer: "); 
            continue;// go to the loop again to prompt value from user
        }
    }
    for(i =0 ; i < number; i++)
    {
         printf("%d",arr_value[i]);
    }
 }
 /* this program runs the enter integer line infinitely, 
    although I tried it with a continue statement.*/

0 个答案:

没有答案