LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 11-01-2005, 04:19 AM   #1
sharapchi
Member
 
Registered: Nov 2004
Location: Turkey
Distribution: slackware
Posts: 119

Rep: Reputation: 15
gets fuction gives warning, why?


Hi,
I am a new programmer on linux. I wrote a short code for testing but gets function gives warning. I was using slackware 10.1 and gcc in 10.1 does not gives warning like this. I am using slackware 10.2 now and gcc 3.3.6 gives it. There is the code and output which gcc gives.

-----------------------

#include <stdio.h>

#define SIZE 100

int main()
{
char str[SIZE];
int k;
int len = 0;

printf("Input a string : ");
gets(str);
printf("String = (%s)\n", str);

for (k = 0; str[k] != '\0'; ++k)
len++;

printf("(%s) = %d\n", str, len);

return 0;
}

----------------------

bash-3.00$ gcc 042_len.c
/tmp/ccU1hwx4.o(.text+0x32): In function `main':
: warning: the `gets' function is dangerous and should not be used.
bash-3.00$

-----------------------
 
Old 11-01-2005, 04:41 AM   #2
Alien Bob
Slackware Contributor
 
Registered: Sep 2005
Location: Eindhoven, The Netherlands
Distribution: Slackware
Posts: 8,559

Rep: Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106
http://home.att.net/~jackklein/ctips01.html#safe_gets

Eric
 
Old 11-01-2005, 08:43 AM   #3
sharapchi
Member
 
Registered: Nov 2004
Location: Turkey
Distribution: slackware
Posts: 119

Original Poster
Rep: Reputation: 15
Thanks but i want to use gets also using that is so dangerous. How can i turn off warnings of gcc?
 
Old 11-01-2005, 08:59 AM   #4
gbonvehi
Senior Member
 
Registered: Jun 2004
Location: Argentina (SR, LP)
Distribution: Slackware
Posts: 3,145

Rep: Reputation: 53
Ok.. let's see: man gcc
Quote:
You can request many specific warnings with options beginning -W, for example -Wimplicit
to request warnings on implicit declarations. Each of these specific warning options
also has a negative form beginning -Wno- to turn off warnings; for example,
-Wno-implicit. This manual lists only one of the two forms, whichever is not the
default.

-w Inhibit all warning messages.

Last edited by gbonvehi; 11-01-2005 at 09:00 AM.
 
Old 11-01-2005, 10:31 AM   #5
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Why not use :
Code:
fgets(str, SIZE, stdin);
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ld: warning drand Linux - Software 2 05-25-2010 04:03 AM
How to make a winmodem fuction on Mandrake 9.2 Impaler Linux - Hardware 1 04-02-2004 06:23 AM
what is this warning in C? h/w Programming 7 10-26-2003 11:16 PM
need perl fuction like c #include statement for header file mrtwice Programming 5 06-19-2003 02:42 PM
fflush fuction in c jetfreggel Programming 13 12-26-2002 06:02 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 03:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration