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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:43:10+00:00 2026-06-09T11:43:10+00:00

I don’t understand what this error is telling me. When I run the program

  • 0

I don’t understand what this error is telling me. When I run the program it should continuously loop until the user enters N (for no more/exit). I don’t understand what is going on. After the first set of inputs, before the user is prompted “Would you like to process a new student” the program throws out that exception.

I’ve run it using Geany (which doesn’t give me any error definition it just crashes), and Visual Studio 2010.

Can someone help?

void draw_bar_chart(int student_id[], int percentage[], int size)
{
    FILE *report;
    int i, j=0, min = 1000000, max = 0, min_pos, max_pos, l;
    char s[20];

    report = fopen("report2.txt", "a");
    fprintf(report, "\n******* BAR CHART (YEARLY TOTAL EXPENSES: YEARLY TOTAL INCOME) *******\n\n");      

    for (i = 0; i < size; i++)
    {
        fprintf(report, "%d%c", student_id[i], ' ');
        if (percentage[i] > 0){
            l = percentage[i]/10; //the lenght of the bar
            if ((percentage[i]%10) > 0)
                l++;
            for (j = 0; j < l; j++)
                s[j] = 'x';
            s[l+1] = '\0';
        } else {
            s[0] = '!';
            s[1] = '\0';
        }

        fprintf(report, "%-20s%6c%d%c\n", s, ' ', percentage[j], '%');

        if (percentage[j] >= 0)
        {
            if (percentage[j] < min)        
            {
                min = percentage[j];        
                min_pos = j;                
            }
            if (percentage[j] > max)    
            {
                max = percentage[j];        
                max_pos = j;                
            }
        }
    }


    fprintf(report, "***lowest percentage:  %d%c (student ID: %d)\n", min, '%', student_id[min_pos]);
    fprintf(report, "***highest percentage: %d%c (student ID: %d)\n", max, '%', student_id[max_pos]);

    fclose(report);

    }
  • 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-09T11:43:11+00:00Added an answer on June 9, 2026 at 11:43 am

    I can see the following errors:

    1. It should be s[l] = ‘\0’, not s[l+1] = ‘\0’.
    2. After you write the bar in s, all occurences of j must be replaced with i.
    3. min_pos and max_pos might be uninitialized.

    The real problem is number 2. You can avoid this kind of mistakes by getting in the habit of putting your variables in the smallest possible scope. i.e. had you written this:

            ...
            fprintf(report, "%d%c", student_id[i], ' ');
    
            /* display percentage */
            {
              char s[20];
    
              if (percentage[i] > 0) {
                int l, j;
    
                l = percentage[i] / 10; // the length of the bar
                if ((percentage[i]%10) > 0)
                    l++;
                for (j = 0; j < l; j++)
                    s[j] = 'x';
                s[l] = '\0';
              }
              else {
                s[0] = '!';
                s[1] = '\0';
              }
    
              fprintf(report, "%-20s%6c%d%c\n", s, ' ', percentage[i], '%');
            }
    
            /* update min, max */
            if (percentage[i] >= 0) {
            ...
    

    Then the code would have been easier to follow and the compiler would have given you an error had you mistakenly used j instead of i after /* update … */. Even better would be to put the percentage display bit in a separate function.

    BTW you don’t need these %c in the format strings, just put the characters in directly. % can be escaped with %%.

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

Sidebar

Related Questions

Don't know what to do with this error. How to add data in SQL
don't understand: in my controller: @json = User.all.to_gmaps4rails do |user| \Title\: \#{user.email}\ end in
Don't understand, if Data.Map is and [] is. I found this out while wondering
Don't know why this conversion fails. SELECT CAST('32.999' AS INT) throws the error saying
don't know better title for this, but here's my code. I have class user
Don't quite understand why this copy constructor is not invoked when I build with
Don't dismiss this as a newbie question! It's not, I'm not, I've tried everything,
Don't really know how to formulate the title, but it should be pretty obvious
I don't know why, but this code worked for me a month ago... maybe
(Don't know if this is strictly on-topic, but I don't see any better Stack

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.