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

  • Home
  • SEARCH
  • 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 7738879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:22:51+00:00 2026-06-01T08:22:51+00:00

Very simple example – hoping for a simple solution: char x[7]; if(fgets(x,5,stdin)) printf(y); else

  • 0

Very simple example – hoping for a simple solution:

char x[7];
if(fgets(x,5,stdin))
    printf("y");
else
    printf("n");

I can’t seem to get it to print “n” when I input more than the byte limit – is there any simple way I could enforce it or catch when it’s surpassed?

As a side question, what example inputs would actually cause an “n” in the above snippet? I’m not really seeing the point right now..

Cheers,
B

  • 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-01T08:22:52+00:00Added an answer on June 1, 2026 at 8:22 am

    fgets returns NULL only if it failed to read anything, which usually means end of file.

    Since fgets reads a line, or as many characters of that line that fit in the buffer, you need to check if your variable x contains a newline character.

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

Sidebar

Related Questions

I've set up a very simple example with LINQ-TO-SQL in WPF. I can get
Here's a very simple example of what I'm trying to get around: class Test(object):
Can someone please help me with a very simple example on how to use
Im trying to get to run a very simple example in liquibase 1.9.5 (see
Here is a very simple example in Java intended to print out all of
I followed a very simple example of autocompletion using ajax and cannot get mine
Can anyone point me to a very simple example(C#4.0) of a WPF Datagrid thats
Can someone provide a very simple example of how to load a datagrid with
I've very simple example, and can't correctly build it, I was using next arguments:
Can someone give me a very simple example of how one would, say, write

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.