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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:10:37+00:00 2026-05-19T03:10:37+00:00

I am running an example from The C Programming Language by Kernighan and Ritchie.

  • 0

I am running an example from The C Programming Language by Kernighan and Ritchie.

#include <stdio.h>

main() {
    long nc;
    nc = 0;
    while (getchar() != EOF)
        ++nc;
    printf("%ld\n", nc);
}

I’m on Mac OS X, so I compile it, run it, type in "12345", press enter for newline (I believe newline is the sixth character?) and then press ctrl-D to send an EOF.

It prints out "6D".

Why is the "D" there?

How do I write a program to just count the 5 chars in "12345" and not the newline?

Should I just subtract one at the end?

How do I get it to stop printing the "D"?

  • 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-19T03:10:37+00:00Added an answer on May 19, 2026 at 3:10 am

    What happens is that the terminal actually echoes your control-D (and prints it out as ^D) when you type it, but then your program overwrites that line with a number and a line-feed. So your one-digit number overwrites the ^, but the D stays there.

    If you enter more than 10 characters, or if change the code by adding a space at the end of your format string ("%ld \n"), then your program would overwrite the ^D (though it would still have been echoed by your terminal)

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

Sidebar

Related Questions

According to Single-Threaded Application with Long-Running Calculation MSDN example, there is a possibility of
I was programming the example code from Frank Luna's book Introduction to 3D Game
I am familier with java programming language I like to extract the data from
An example from (the excellent) Unix Programming Environment considers an address book: John Perkins
i have tried to get the sine wave example running on an AsioOut, but
I am trying to get an example application running with blackberry-py. I adhered to
When running the MVC 2 Areas example that has a Blog Area and Blog
I am running a sample push notification example.I have done the c2dm signup and
I'm running a query that retrieves 20 rows (for example). I want to know
I was already running a sub-website under following path http://example.com/sub-site/ Now, I have created

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.