Getting multiple values with scanf()

前端 未结 7 1140
孤街浪徒
孤街浪徒 2020-12-03 03:03

I am using scanf() to get a set of ints from the user. But I would like the user to supply all 4 ints at once instead of 4 different promps. I know I can get one value by do

7条回答
  •  自闭症患者
    2020-12-03 03:19

    Could do this, but then the user has to separate the numbers by a space:

    #include "stdio.h"
    
    int main()
    {
        int minx, x, y, z;
    
        printf("Enter four ints: ");
        scanf( "%i %i %i %i", &minx, &x, &y, &z);
    
        printf("You wrote: %i %i %i %i", minx, x, y, z);
    }
    

提交回复
热议问题