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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:17:53+00:00 2026-06-14T13:17:53+00:00

It is not equal: fgets (answer, 256, stdin); if (strncmp(answer, sta, 4) == 0)

  • 0

It is not equal:

fgets (answer, 256, stdin);

if (strncmp(answer, "sta", 4) == 0)
  printf("omg, it's equal"); 

This code is:

fgets (answer, 4, stdin);

if (strncmp(answer, "sta", 4) == 0)
  printf("omg, it's equal"); 

Why? It is because in the first, answer doesn’t have \0 at the 4th place I guess (if I change it to 3 instead of 4 it works). But what does fgets do? String answer in the first is str \whitespace*253\0"? And in the second it is str\0? Thank you.

  • 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-14T13:17:55+00:00Added an answer on June 14, 2026 at 1:17 pm

    fgets (unlike gets) includes the trailing \n corresponding to the return pressed at the end of the line. If you put 3 as the limit it truncates the string, discarding the \n.

    From the manpage:

    fgets() reads in at most one less than size characters from stream and
    stores them into the buffer pointed to by s. Reading stops after an
    EOF or a newline. If a newline is read, it is stored into the buffer.
    A terminating null byte ('\0') is stored after the last character in
    the buffer.

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

Sidebar

Related Questions

why d is not equal b in this example? unsigned int z = 176400;
From this question I learned Double.NaN is not equal to itself. I was verifying
Afternoon, How would i set this as not equal to? I am basically trying
What is if not equal statement in beanshell ? if this is equal :
Is this the notation to use for Not Equal To in JS, in jquery
I'm using the next code to check if string is not equal to value
I keep seeing variations of this: Not equal != Not equal, equal !== Which
Can someone explain this to me? In C# double.NaN is not equal to double.NaN
According to this , !==! is the not-equal string operator. Trying it, I get:
float f = 0.7; if( f == 0.7 ) printf(equal); else printf(not equal); Why

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.