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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:18:43+00:00 2026-06-13T12:18:43+00:00

char s; list<char> inp; while(s=fgetc(stdin),s!=EOF) { inp.push_back(s); printf(%c,s); } for(list<char>::iterator n=inp.begin();n!=inp.end();n++) { cout<<*n; }

  • 0
char s;
list<char> inp;

while(s=fgetc(stdin),s!=EOF)
{
    inp.push_back(s);
    printf("%c",s);
}
for(list<char>::iterator n=inp.begin();n!=inp.end();n++)
{
    cout<<*n;
}

The while loop in the above code is never being terminated ? This may happen if EOF is never recieved from stdin. How can this happen?

  • 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-13T12:18:44+00:00Added an answer on June 13, 2026 at 12:18 pm

    Make s an int. The fgetc() function returns an int, since EOF is defined as one.

    int s;
    

    Change it to:

    while((s=fgetc(stdin)) != EOF)
    {
        inp.push_back(s);
        printf("%c",s);
    }
    

    Also, EOF is not read automatically when using stdin unless you are using a pipe.

    Think about it this way…

    The program waits for the user to type in characters. How would the program know if EOF has been reached or the user is thinking about what to type next. The user has to send EOF to the program by typing ctrl+D.

    The exception is when you have redirected stdin to a pipe. For example, if you compiled your program to a.out:

    cat "myfile" | a.out
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

struct list{ char *Name; }; void chekFC(struct list *newList){ char *fC = newList->Name; printf(%s\n,
Problem: How do I loop through a list, look at the first char in
//------------------------------ //creating dynamic array to send std::list<char> list; char in=NULL; while(1) { scanf(%c,&in); if(in=='\n')
I have 3 files: 1) cpf0.ml type string = char list type url =
I'm having a problem and can't seem to find the solution.. int linearSearch(nodeptr list,char
I am having list of char array by that I want to store all
I have some std::list<char> list_type Now I have to supply contents of the list
I was trying to make an array-based linear list, then I compiled this: char
I'm writing some code that has a lot of substitution. There's a list<char> productions
public Alphabet(params char[] list) { this.ExceptionInitializer(); try { if (list != null) _alphabet =

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.