Thread: Loading numbers into array problem

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Dec 2022
    Posts
    1

    Unhappy Loading numbers into array problem

    Hello i am trying to make code which will request user for his phone number (on one line), that number will be stored in array number, everything works ok till i dont type less then 10 numbers and press enter, cycle is waiting for next number/s on new line but i want program to give message like: number is too short or too long , type that number again: i have tried many options with while cycle and do while but none of them works properly
    Code:
    #define ARRAYSIZE(a)   (sizeof(a) / sizeof(a[0]))
    int main()
    {
      int number[10];
       printf("type your number: \n");
       for (int i = 0; i < ARRAYSIZE(number); i++)
       {
        scanf("%1d",&number[i]); //fe input: 033232313 is correct 
                //123 is incorrect user will be able to type numbers again 
       }
      ...
    }
    Thanks in advance for any help...
    Last edited by grepawk; 12-07-2022 at 11:35 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Having a problem with random numbers in array
    By Man_Onaizah in forum C Programming
    Replies: 2
    Last Post: 05-05-2016, 08:08 AM
  2. problem store random numbers in array
    By Xavi Camps in forum C Programming
    Replies: 7
    Last Post: 01-13-2015, 12:03 AM
  3. Replies: 2
    Last Post: 01-29-2014, 05:17 PM
  4. Array problem averaging numbers
    By Thedon in forum C Programming
    Replies: 6
    Last Post: 10-27-2011, 11:27 AM
  5. problem with loading array of class objects
    By McElmurry in forum C++ Programming
    Replies: 1
    Last Post: 12-04-2010, 03:34 AM

Tags for this Thread