how to read random number of int in array

后端 未结 4 1408
庸人自扰
庸人自扰 2021-01-28 11:43

i want to read space separated integer into an array and when i press enter it should stop reading at any point of time, how to implement loop for this prog

4条回答
  •  孤街浪徒
    2021-01-28 12:04

    A good way is to use getchar() and a character to check ENTER in your program by checking ASCII value

    while(1)
        {
            char d;
            d=getchar();
    
              if(d==13 || d==10) break;
                arr[j++]=d-'0';
    
        }
    

    it will terminate as soon as you will press enter. More discussion is already provided on this So post

提交回复
热议问题