Why is it dangerous?



'evening.

I'm not new to C and have been programming in it since I was 8 but
here's a strange problem I've never seen before.

When I compile a program from our C course with a windows compiler
there is no problem but when I try to compile it with a linux compiler
it complains that

a_03.c:(.text+0x4d): warning: the `gets' function is dangerous
and should not be used.

Is linux more dangerous than windows? Where can I download a
non dangerous gets function? I have never used gets before is
there undefined behavior somewhere?


Here is a trimmed down example program from my assignment that
demonstrates the problem

#include <stdio.h>
#include <malloc.h>

void main()
{
char *string;
printf("enter string (max 2000 chars): ");
fflush(stdin);
fflush(stdout);
string = (char *)malloc(2001);
if(!string) exit(1);
gets(string);
printf("you entered: %s\n", string);
free(string);
exit(0);
}

On windows with TurboC and Lcc no error is printed. On linux with
gcc it says gets is dangerous.

Please advise my instructor says gcc is overly pedantic.


.



Relevant Pages

  • Re: free database server for desktop application with ado.net driv
    ... I've used MySQL on Windows since its 3.x days, ... So what if it is GNU and supports linux? ... You're missing the point - you do not have to compile it yourself. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Is CMUCL insane? P.S. Me vs. CLM (Common Lisp Music)
    ... Or to build Windows without a working version of Windows. ... why are you trying to compile CMUCL?" ... let's assume I use Linux and not an emulator here... ...
    (comp.lang.lisp)
  • Re: PcLinux
    ... Mind zap every time I see gcc... ... despicable than the simple limited capabilities of OS/2, ... can really quibble about is open for debate even between linux distros. ... herd of rabid badgers would be preferable to using Windows, ...
    (rec.crafts.metalworking)
  • Re: [SLE] Re: GNOME vs KDE Redoux--thoughts
    ... Since when does a compiler come with Windows? ... It is true that most windows users know nothing about programming. ... I would guess, that, like you, a great many Linux users know little about ... a compiled language, and I did compile some custom stuff from the Windows ...
    (SuSE)
  • Re: [SLE] Re: GNOME vs KDE Redoux
    ... Since when does a compiler come with Windows? ... It is true that most windows users know nothing about programming. ... Also, 10 years ago, Linux was not so popular, so most tinkerers (or ... In fact, many people, me included, compile things in Linux without really ...
    (SuSE)