You are not logged in. Please login at www.codechef.com to post your questions!

×

use of gets() in c++(gcc 6.3)

I have coded on code blocks and the language I have used is c++ but when I compile in the code chef compiler by uploading the file gets() function shows up compilation error despite including the header file <stdio.h>. error says gets() not declared;

asked 22 Jul '17, 20:22

himanish's gravatar image

2★himanish
1113
accept rate: 0%


See the following link.

http://www.cplusplus.com/reference/cstdio/gets/

Under the heading Compatibility, it's written that: The most recent revision of the C standard (2011) has definitively removed this function from its specification.

This could be the reason.

link

answered 22 Jul '17, 20:54

c_utkarsh's gravatar image

5★c_utkarsh
1.1k5
accept rate: 17%

edited 22 Jul '17, 20:54

Using the gets() function is dangerous, as it suffers from buffer overflow issue. You should refrain from using that.I guess you want take input with spaces there are some alternatives to gets() try them..

link

answered 22 Jul '17, 20:46

srikanth_16's gravatar image

1★srikanth_16
2854
accept rate: 28%

If you want to take input with spaces try using getline.

link

answered 22 Jul '17, 23:10

sudip_95's gravatar image

4★sudip_95
7556
accept rate: 10%

Due to buffer overflow issue, gets is removed from cpp standards.Instead you can use fgets to fulfill your needs in your program. Hope will help you. For more details visit the following link. http://www.geeksforgeeks.org/gets-is-risky-to-use/

link

answered 23 Jul '17, 01:14

droy0528's gravatar image

4★droy0528
956
accept rate: 16%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×1,911
×8

question asked: 22 Jul '17, 20:22

question was seen: 3,030 times

last updated: 23 Jul '17, 01:14