How to test input is sane

后端 未结 6 1137
一个人的身影
一个人的身影 2020-12-11 11:38

Consider the following simple C program.

//C test

#include

int main()
{
   int a, b, c;

   printf(\"Enter two numbers to add\\n\");
   scan         


        
6条回答
  •  被撕碎了的回忆
    2020-12-11 12:03

    You can use like:

    if( scanf("%d%d",&a,&b) == 2)
    {
       //two integer values has been read successfully
       //do your stuff here
    }
    else
    {
       //Wrong input
    }
    

提交回复
热议问题