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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:27:39+00:00 2026-05-26T06:27:39+00:00

Here is the portion of my C program: FILE *fin_length; int c; int countNewLines

  • 0

Here is the portion of my C program:

FILE *fin_length;
int c;
int countNewLines = 0;

fin_length = fopen( argv[1], "r" );

while( ( c == fgetc( fin_length ) ) != EOF ) {

    if( c == 10 ) countNewLines++;
}

fclose( fin_length );

I run the program with command line arguments ./a.out myMessage.dat. myMessage.dat is 5 lines long, where each line contains nothing more than a short sentence. Therefore, I expect the loop to find these 5 lines with if( c == 10 ) and add one to countNewLines every time it finds a carriage return.

Why am I getting an infinite loop here?

  • 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-26T06:27:39+00:00Added an answer on May 26, 2026 at 6:27 am

    while( ( c == fgetc( fin_length ) ) != EOF ) {

    You have too many equal signs. This should be

    while( ( c = fgetc( fin_length ) ) != EOF ) {

    When you use ==, you end up with two comparisons. The first is a comparison between c and the return value of fgetc().

    The second comparison compares that result (which is either true or false) with EOF. I have not looked up the value of EOF, but it is certainly not 0 or 1 – meaning that the second comparison will never return false.

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

Sidebar

Related Questions

Here is a portion of my app.yaml file: handlers: - url: /remote_api script: $PYTHON_LIB/google/appengine/ext/remote_api/handler.py
Here is a portion of my code: var styles:String = .keyword{color: #ff0000;} .comment{color: #00ff00;};
[ edit ] For the record, here's the problem portion of the query, which
I needed some help in trying to optimize this code portion ... Basically here's
Ok so I'm doing a program for class when I run across a bug
I'm trying to set up a program to record a portion of an internet
Looking for help on writing a Perl program that takes an input file and
I have a program that is saves information like a list of names, file
I am implementing a netcat clone and currently need a way to run command-line
Here is my Python program: import re print re.findall( ([se]{2,30})ting, testingtested ) Its output

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.