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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:35:17+00:00 2026-05-31T05:35:17+00:00

Say, I have a file that contains 100000 integers. Each integer is on a

  • 0

Say, I have a file that contains 100000 integers. Each integer is on a new line in the file.
My task is to firstly store these integers in an array and then secondly, find the number of inversions possible in these 100000 numbers using the mergesort algorithm. The latter part which I’ve managed to do.

I’ve written the code to read each line and then store every single digit in a 2 Dimensional array. For instance say 54667 is on the first line and 67890 is on the second line

Then the code that I’ve written performs this

arr[i][j]=5 arr[i][j+1]=4 arr[i][j+2]=6........(and so on)
 arr[i+1][j]=6 arr[i+1][j+1]=7 arr[i+1][j+2]=8......

and then I have to reconstruct these integers by multiplying by suitable powers of 10, and store them in a 1 Dimensional array.

However, writing while writing this code I somehow was convinced that there has to be a simpler way to do this in C. As in, isn’t there some function or command that makes this job easier?

  • 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-31T05:35:18+00:00Added an answer on May 31, 2026 at 5:35 am

    Yeah, just use fgets and strtol every line.

    char line[LEN];
    long array[NUM];
    int i;
    
    while (i < NUM && fgets(line, sizeof(line), stdin))
        array[i++] = strtol(line, NULL, 10);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .rtf file that contains nothing but an integer, say 15. I
If I have a dbml file that contains say a Customer class with say
Say I have a file, t.txt, that contains the following two lines: one two
Let say I have a file that contains a serialized object by BinaryFomatter. Now
Let say I have a project that contains a packages.config file. Now when I
Let us say I have a HTML page that contains a javascript file: The
Say i have a .html file that contains a web design and has variables
Say I have a file at the URL http://mywebsite.example/myscript.txt that contains a script: #!/bin/bash
Let's say I have a tab-delimited text file that contains data arranged in columns
Let's say I have an existing trivial XML file named 'MyData.xml' that contains the

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.