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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:16:59+00:00 2026-05-20T05:16:59+00:00

Will the gets() function from C language (e.g. from glibc) stop, if it reads

  • 0

Will the gets() function from C language (e.g. from glibc) stop, if it reads a zero byte ('\0') from the file ?

Quick test: echo -ne 'AB\0CDE'

Thanks.

PS this question arises from comments in this question: return to libc – problem

PPS the gets function is dangerous, but it is a question about this function itself, not about should anybody use it or not.

  • 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-20T05:17:00+00:00Added an answer on May 20, 2026 at 5:17 am

    The behavior of gets() is that it stops when a newline character is encountered or if EOF is encountered. It does not care if it reads \0 bytes.

    C99 Standard, 7.19.7.7

    Synopsis

       #include <stdio.h>
    
       char *gets(char *s);
    

    Description

    The gets function reads characters from the input stream pointed to by stdin, into the
    array pointed to by s, until end-of-file is encountered or a new-line character is read.
    Any new-line character is discarded, and a null character is written immediately after the
    last character read into the array.

    From GNU libc documentation: http://www.gnu.org/software/libc/manual/html_node/Line-Input.html#Line-Input

    — Deprecated function: char * gets (char *s)

    The function gets reads characters from the stream stdin up to the next newline character, and stores them in the string s. The newline character is discarded (note that this differs from the behavior of fgets, which copies the newline character into the string). If gets encounters a read error or end-of-file, it returns a null pointer; otherwise it returns s.

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

Sidebar

Related Questions

If the number of documents is more will the querying of data gets slower
I am deleting segments after they gets indexed then how nutch will get that
Will Java code built and compiled against a 32-bit JDK into 32-bit byte code
Will GHC perform tail-call optimization on the following function by default? The only weird
Previously I asked about how I could call separate values from a text file
I'm trying to make a call to a DLL function (via GetProcAddress etc) from
I'm currently writing an iPhone application which gets some data from the user and
I would like to be able to run a function from the directory where
A PHP function I am writing pulls a small bit of HTML data from
When i remove the parameter 'ajax' from from the .queue() function, my ajax calls

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.