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

The Archive Base Latest Questions

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

Today, I wrote a simple piece of code that uses getchar() to count the

  • 0

Today, I wrote a simple piece of code that uses getchar() to count the characters you input. But when I compile it on Cygwin, it does not work. It always prints 0, but I never input anything or I can’t input any characters it prints 0.

However, if I compile it with VC++6.0, it works.

#include<stdio.h>
int main(void)
{
 long nc;

 nc = 0;
 while(getchar() != EOF)
    ++nc;
 printf("The total of characters you inputed is %ld.\n", nc);
 return 0;
}
  • 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-27T21:02:48+00:00Added an answer on May 27, 2026 at 9:02 pm

    This email thread talks about a bug that sounds much like yours, but I can’t see that there are any follow-ups to it.

    I would be interested to know what happened when you try

    while(getc(stdin) != EOF)

    and if that doesn’t work, try
    while(fgetc(stdin) != EOF)

    All of them should work, though this page suggests there could be implementation differences between these functions.

    Another thing you could try is to print the ASCII value of what you get:

    printf("%d\n",(int)getchar());

    Also, try piping output from a file instead of typing it in the console. Create a file input.txt, put some characters in it, and do

    cat input.txt | ./program

    EDIT: You write running cat and piping it works. I would say simply update your Cygwin version. You have encountered a bug. Get the newest versions of Cygwin and the compiler, and you should be good to go. Another option is to use scanf.

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

Sidebar

Related Questions

I wrote this simple program today, but I found that cin.get() refuses to work
Today, I found out that you can write such code in C++ and compile
Today I wrote a small predicate to find matching symbols in a container. But
Ok, I wrote this question up earlier today but I decided to delete it
Today I was able to write a simple C++ program that granted a user
Today I'm trying the xtend to write a simple program. Looks good, but it
I wrote a heredoc three weeks ago that was working great, and until today
Today, without much thought, I wrote a simple function return to a char* based
I just wrote a simple DirectShow Filter (which inherits from CTransformFilter). But I want
Today I was happily coding away when I got to a piece of code

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.