Check if user input into an array is too long?

前端 未结 6 2167
执笔经年
执笔经年 2021-01-24 18:19

I am getting the user to input 4 numbers. They can be input: 1 2 3 4 or 1234 or 1 2 34 , etc. I am currently using

int array[4];
scanf(\"%1x%1x%1x%1x\", &ar         


        
6条回答
  •  自闭症患者
    2021-01-24 18:57

    It would probably be easier for you to change your program, so that you ask for one number at a time - then you ask 4 times, and you're done with it, so something along these lines, in pseudo code:

    i = 0
    while i < 4
    ask for number
    scanf number and save in array at index i
    

提交回复
热议问题