Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7879947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:01:14+00:00 2026-06-03T04:01:14+00:00

I have a program that needs two integers to be entered to set up

  • 0

I have a program that needs two integers to be entered to set up a 2d array and if you enter a letter then the program does not work.

Is there any way to check if it is a number that has been entered or to limit what is pressed on the key board to only numbers?

Once the number has been entered it is scanned into a variable to set up the array.

Here is the example of code:

#include <stdlib.h>
#include <stdio.h>
#include <time.h>

int x;
int y;

int main(void){

    int array[x][y];
    int i;
    int j;
    srand(time(NULL));


printf("Please Enter Size X Of Array:");
scanf("%d",&x);
printf("\n");
printf("please Enter Size Y Of Array:");
scanf("%d",&y);


    printf("\n Randomised Numbers Table \n\n");

    for (i = 0; i < x; i++){

        for (j = 0; j < y; j++){
            array[i][j] =(rand()%10000);
            printf("%d \t", array[i][j]);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T04:01:16+00:00Added an answer on June 3, 2026 at 4:01 am

    The best way to deal with this is to loop until you have valid input. With bash, you can use the regular expression operator to make sure the string is valid before proceeding.

    # Loop until your input is valid.
    unset REPLY
    until [[ $REPLY =~ ^[0-9]{2}$ ]]; do
        read -p 'Digit: '
    done
    echo "You entered: $REPLY"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program that needs a lot of memory and want to set
In my vb program, I have two forms that work together to allow you
I have a program that streams media, which creates two huge MemoryStreams, and then
I have a program that needs several third-party libraries, and at the moment it
I have a Flash program that needs to make url requests to send data
In an embedded program I have a screen object that needs to manage a
I'm making a C program that needs to use two stacks. One needs to
I have one table [table] with two columns that needs to be filtered: [column1]
I am making a program that makes use of two Array Lists. I've researched
I have a program that needs to repeatedly compute the approximate percentile (order statistic)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.