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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:31:02+00:00 2026-05-27T03:31:02+00:00

OSX 10.6.8, GCC 4.2 86_64 #include <stdio.h> /* count lines in input */ main()

  • 0

OSX 10.6.8, GCC 4.2 86_64

#include <stdio.h>

/* count lines in input */
main()
{
    int c, nl;

    nl = 0;
    while ((c = getchar()) != EOF)
        if (c == '\n')
            ++nl;
    printf("%d\n", nl);
}

Run

./a.out

press ctrl+d to send EOF

0D

It should be just 0. Why does it append D? What does it mean?

  • 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-27T03:31:02+00:00Added an answer on May 27, 2026 at 3:31 am

    I’ve seen this one – it confused me, too.

    The terminal is echoing ^D and then the 0 is output from the program, overwriting the caret.

    You can demonstrate this by changing the print format in your program to "\n%d\n".


    When asked ‘Why?’, I went exploring. The answer is in the tty settings. For my terminal, the output from stty -a is:

    speed 9600 baud; 65 rows; 120 columns;
    lflags: icanon isig iexten echo echoe -echok echoke -echonl echoctl
        -echoprt -altwerase -noflsh -tostop -flusho pendin -nokerninfo
        -extproc
    iflags: -istrip icrnl -inlcr -igncr ixon -ixoff ixany imaxbel iutf8
        -ignbrk brkint -inpck -ignpar -parmrk
    oflags: opost onlcr -oxtabs -onocr -onlret
    cflags: cread cs8 -parenb -parodd hupcl -clocal -cstopb -crtscts -dsrflow
        -dtrflow -mdmbuf
    cchars: discard = ^O; dsusp = ^Y; eof = ^D; eol = <undef>;
        eol2 = <undef>; erase = ^?; intr = ^C; kill = ^X; lnext = ^V;
        min = 1; quit = ^\; reprint = ^R; start = ^Q; status = ^T;
        stop = ^S; susp = ^Z; time = 0; werase = ^W;
    

    Notice the echoctl at the end of the second line – it is for ‘echo control characters’.

    $ stty -echoctl
    $ cat > /dev/null
    asdsadasd
    $ stty echoctl
    $ cat > /dev/null
    asasada^D
    $
    

    You can’t see it, but for each cat command, I typed a Control-D at the end of the line of asd characters, and a second one after hitting return. The prompt erased the second echoed ^D in the second example.

    So, if you don’t like the control characters being echoed, turn the echoing off:

    stty -echoctl
    

    The shell can also get in the way; I experimented with Control-R and my shell (bash) decided to go into

    (reverse-i-search)`': aasadasdadadasdadadadadadsad
    

    I’d typed the unoriginal sequence of ‘asd’ characters and then typed Control-R, and this is where I ended up in the shell. I interrupted; I’m not sure what a reverse-i-search is, but I suspect it is Emacs-ish; it was not what I expected.

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

Sidebar

Related Questions

I just tried to write a simple C program on OSX Lion #include <stdio.h>
Using glew, I'm trying to link the simple program #include </usr/include/GL/glew.h> int main (int
I am using GCC on Mac OSX. I am trying to get GCC to
Macros for GCC/G++ to differentiate Linux and Mac OSX?
In OSX I have the following code. Using gcc 4.0.1. I'm new to OSX
On OSX 10.6.4 with iPhone SDK and Xcode 3.2.1 installed: $ gcc foo.c -arch
I think I have several versions of gcc installed on my Mac OSX. Right
OSX Lion, Xcode 4.2, GCC 4.2 I get the following error installing bson_ext 1.4.1
So, I'm messing around with some interposing code on OSX (gcc 4.2.1) and I'm
Why does the program listed below run on mac osx and linux but not

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.