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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:29:57+00:00 2026-05-31T19:29:57+00:00

This program takes the first number in a file and indicates how many numbers

  • 0

This program takes the first number in a file and indicates how many numbers are going to be after it, then does various other things with the numbers that follow.

It seems like scanf is causing an infinite loop when trying to read from the file. WHen I run the program not even the check at 1 works

Here is the code:

#include <stdio.h>

int main(void) {
        int N, a, n;
        int x=0;
        int t=0;
        printf("1"); //Check
        scanf("%d", &N);
        printf("2"); //Check
        int nums[N];
        int i;
        printf("%d", &N);  //Check
        for (i=0; i<N; i++)
        {
                scanf("%d", &nums[i]);
                t+=nums[i];

                if (nums[i] > x) x=nums[i];

                if (i=0 || nums[i] < n) n = nums[i];
        }
        a = t/N;   
        printf("Number Processed: \t%d\n", &N);
        printf("Maximum: \t%d\n", &x);
        printf("Minimum: \t%d\n", &n);
        printf("Total: \t%d\n", &t);
        printf("Average: \t%d\n", &a);
}

The way i run the program is

gcc -lab16
./a.out <in1

where in1 is text and has the numbers

7
6
-30
90
3903
-934
443
445

Thanks for your time.

  • 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-31T19:29:59+00:00Added an answer on May 31, 2026 at 7:29 pm
    if (i=0 || nums[i] < n) n = nums[i];
    

    you are assigning i = 0, so the loop never realy advances! You probably wanted i == 0. This is causing the infinite loop.

    Other issue: int nums[N]; – if you want an array of dynamic [determined in run-time] size, you will probably need to malloc() it.

    Update: note that int nums[N] is valid in C99, so if your assigment is assuming C99 you should not worry about this issue. Otherwise – malloc() will be needed:

    int* nums = (int*) malloc(sizeof(int) * N)
    

    And don’t forget to free(nums) before the program ends, or you will get memory leak.

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

Sidebar

Related Questions

I am building a program that takes an input file in this format: title
This program takes 2 numbers from user input, asks them whether they'd like to
I wrote this function to communicate with an external program. Such program takes input
there is this check-in-out program here at my workplace, it only takes the data
I have a program, that takes a long time to load. Because of this,
This program stores pairs in a map, counting the number of times a word
This program reads emails (really just a .txt file structured like an email) and
I made a program in Xcode, being a simple calculator that takes a first
I am writing a program that takes in an input file from the user.
This program I use has it's own variables to set when you run it,

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.