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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:51:10+00:00 2026-05-27T07:51:10+00:00

I am trying to print a file in reverse order. I am using arrays

  • 0

I am trying to print a file in reverse order. I am using arrays to save each lines data. So far I was able to print every line in a normal order.

index is the number of lines I am referring to and FuncIndex the same thing but has been declared again in the function.

file = fopen("../quotes.data","r");
while (NumOfField == 8) {
    NumOfField = fscanf(file,"%d,%c,%d,%d,%c,%c,%lf,%lf", &quote[index], &roomletter[index], &length[index], &width[index], &paint[index], &ceiling[index], &cost[index], &setup_cost[index]);
    index++;
}
index--;
fclose(file);

In Function:

int FuncIndex;
for (FuncIndex = 0; FuncIndex <= index; FuncIndex++) {
    printf("\n%5d   %1c   %3d    %3d    %1c      %1c    %8.2lf %6.2lf", quote[FuncIndex], roomletter[FuncIndex], length[FuncIndex], width[FuncIndex], paint[FuncIndex], ceiling[FuncIndex], cost[FuncIndex], setup_cost[FuncIndex]);
}

Now I tried changing the for loop to:

for (FuncIndex = index; FuncIndex >= 0; FuncIndex--) >

But the output prints empty. Although when I change the 0 to any number, that corresponding line gets printed.

The output That prints is:

Quote Room Length Width Paint Ceiling     Cost  Setup
===== ==== ====== ===== ===== =======  =======  =====
531   A    10     10    b      n       96.00 100.00
531   B    15     15    b      n      144.00   0.00
531   C    20     20    b      n      192.00   0.00

I am looking to get this output reversed like:

Quote Room Length Width Paint Ceiling     Cost  Setup
===== ==== ====== ===== ===== =======  =======  =====
531   C    20     20    b      n      192.00   0.00
531   B    15     15    b      n      144.00   0.00
531   A    10     10    b      n       96.00 100.00

Please excuse me if I putted the output in the code section because then the formatting would change

Thank you.

  • 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-27T07:51:11+00:00Added an answer on May 27, 2026 at 7:51 am

    Ok here is the answer to my question:

    the EOF was the trick

    for (FuncIndex = index; FuncIndex != EOF; FuncIndex--)
    

    Basically, in here you are saying that whatever the number of index is (Number of Lines) put it in the FuncIndex and then one by one (from the highest number) check each line until its not the end of line anymore.

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

Sidebar

Related Questions

I am trying to print a XML file using lxml and Python. Here is
I am trying to print out lines from a file which match a particular
In Perl, I'm trying to read a file line by line and process each
I'm trying to print a file using straight HTML, however, I am having difficulties
I am trying to print an image file on printer using QWebview but instead
I'm trying to print xls file to pdf using soffice on windows machine. i
I'm trying to print a pcl file programatically in c#. I'm using the following
I am having some trouble trying to print from a file. Any ideas? Thanks
I am trying to print a report that contains a bar graph using the
Why does trying to print directly to a file instead of sys.stdout produce 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.