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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:54:37+00:00 2026-06-17T02:54:37+00:00

What is the value compared in the following code? while ((c = getchar()) !=

  • 0

What is the value compared in the following code?

while ((c = getchar()) != EOF)
        if ( c == '\n')

I know that '\n' is a constant variable because of the single quote. I know that it represents the numerical value of the character on the ASCII table, right? That is equal to 110. But what does

((c = getchar()) != EOF) return?

Thanks

  • 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-17T02:54:38+00:00Added an answer on June 17, 2026 at 2:54 am

    The crucial point is that c must be an int:

    int c;
    
    while ((c = getchar()) != EOF) { char read_value = c; /* ... */ }
    

    It is assumed that an int can hold more values than a char, or at least more values that the system’s narrow multibyte encoding uses*, and getchar returns a special constant EOF when there it failed to read more data. Otherwise, it is guaranteed that you can convert c to a char and obtain the value of the character that was read.

    It is a common mistake to declare c itself as a char, in which case the loop might never terminate, since you might not be able to capture the special value EOF, or otherwise there would be a perfectly valid character which would be indistinguishable from (char)EOF.

    *) For example, it would be perfectly fine if both a char and an int were 32 bits wide on a given platform, as long as, say, the narrow stream could only return units with values in the range [-128, 128), and you could use -200 as EOF.

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

Sidebar

Related Questions

I have a function, that returns the next higher value of a Dictionary-Keys-List compared
I currently have the following code that produces the desired results I want (
I have a part of a code that does the following: It reads in
I was playing around with this code. http://programmersvoice.com/tag/code And I noticed that the following
Possible Duplicate: C# okay with comparing value types to null Consider the following code
I understand that using the === compares type, so running the following code results
I have to compare a value in a string array to that of a
I need to compare the value of a column (LASTNAME) with a system variable
I've got the following bit of code as part of a SQL Query: INSERT
I have code like the following, class _Process(multiprocessing.Process): STOP = multiprocessing.Manager().Event() def __init__(self, queue,

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.