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

  • SEARCH
  • Home
  • 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 8826913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:15:33+00:00 2026-06-14T07:15:33+00:00

Basically I have a C program where the user inputs a number (eg. 4).

  • 0

Basically I have a C program where the user inputs a number (eg. 4). What that is defining is the number of integers that will go into an array (maximum of 10). However I want the user to be able to input them as “1 5 2 6” (for example). I.e. as a white space delimited list.

So far:

#include<stdio.h>;

int main()
{
    int no, *noArray[10];    
    printf("Enter no. of variables for array");
    scanf("%d", &no);

    printf("Enter the %d values of the array", no);
    //this is where I want the scanf to be generated automatically. eg:
    scanf("%d %d %d %d", noArray[0], noArray[1], noArray[2], noArray[3]);

    return 0; 
}

Not sure how I might do this?

Thanks

  • 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-14T07:15:34+00:00Added an answer on June 14, 2026 at 7:15 am

    scanf automatically consumes any whitespace that comes before the format specifier/percentage sign (except in the case of %c, which consumes one character at a time, including whitespace). This means that a line like:

    scanf("%d", &no);
    

    actually reads and ignores all the whitespace before the integer you want to read. So you can easily read an arbitrary number of integers separated by whitespace using a for loop:

    for(int i = 0; i < no; i++) {
      scanf("%d", &noArray[i]);
    }
    

    Note that noArray should be an array of ints and you need to pass the address of each element to scanf, as mentioned above. Also you shouldn’t have a semicolon after your #include statement. The compiler should give you a warning if not an error for that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I basically have a program that filters records from one excel file to another
Basically I have a part of my program (it's for Vector solving) that is
Basically, I want to have my program retrieve various variables from the hard drive
Basically, i have a program that is given a 4 meg compressed file, it
I have a Java program that generates Java classes for my application. Basically it
I am basically doing a tutorial but my program seems to have errors that
So I have to do a program that basically tests that an XML text
Basically I have a windows form C# program that uses a SQL Server Express
Basically I have a program that has 6 sliders that send a value through
So we have a program that the user can use by copying text from

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.