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 6693037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:56:12+00:00 2026-05-26T05:56:12+00:00

I need to read something like: 5 60 35 42 2 38 6 5

  • 0

I need to read something like:

5 60 35 42
2 38 6
5 8
300 1500 900

And then save the first line in an array. After calling other functions do the same with the next line, and so on.

I try with gets() and then use sscanf() to scan the integers from the string, but I don’t know how to read n numbers from a string.

  • 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-05-26T05:56:12+00:00Added an answer on May 26, 2026 at 5:56 am

    I’ve seen input files like this for competitions before. If speed is more of an issue than error detection, you could use a custom routine. Here’s one similar to that I use:

    void readintline(unsigned int* array, int* size) {
        char buffer[101];
        size=0;
        char* in=buffer;
        unsigned int* out=array;
        fgets(buffer, 100, stdin);
        do {
            *out=0;
            while(*in>='0') {
                *out= *out* 10 + *in-'0';
                ++in;
            }
            if (*in)
                ++in; //skip whitespace
            ++out;
        } while(*in);
        size = out-array;
    }
    

    It will destroy your memory if there’s more than 100 characters on a line, or more numbers than array can hold, but you won’t get a faster routine to read in lines of unsigned ints.

    On the other hand, if you want simple:

    int main() {
        std::string tmp;
        while(std::getline(std::cin, tmp)) {
            std::vector<int> nums;
            std::stringstream ss(tmp);
            int ti;
            while(ss >> ti) 
                nums.push_back(ti);
            //do stuff with nums
        }
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to read in an Intel Hex file which looks something like this:
For Example: If I need to read a multiple line input like(and I dont
I need to read an XML file using Java. Its contents are something like
I need to read a CSV file, update a field, then save the changes.
I have a command which outputs something like that: lucid32 lucid64 I need to
What do I use if I need something like Tomcat server that is always
I need to read line by line from text file (log files from server)
Sometimes we deploy applications behind customer firewall and we need read only access to
I need to read from a variety of different text files (I've some delimited
I need to read selected files, matching on the file name, from a remote

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.