Chinaunix

标题: 干嘛不给用getch(),gets()函数??? [打印本页]

作者: lluct    时间: 2004-03-01 09:23
标题: 干嘛不给用getch(),gets()函数???
windows下没事.可到了linux下,老出现错误!!!why?
作者: lenovo    时间: 2004-03-01 09:29
标题: 干嘛不给用getch(),gets()函数???
哪里出错了,说清楚点。
把代码贴出来。
作者: carol1980    时间: 2004-03-01 09:34
标题: 干嘛不给用getch(),gets()函数???
SYNOPSIS
       #include <stdio.h>;

       int fgetc(FILE *stream);
       char *fgets(char *s, int size, FILE *stream);
       int getc(FILE *stream);
       int getchar(void);
       char *gets(char *s);
       int ungetc(int c, FILE *stream);


       #include <curses.h>;
       int getch(void);
作者: BingbingNorth    时间: 2004-03-01 09:34
标题: 干嘛不给用getch(),gets()函数???
getch()是curses库的函数,不是标准输入输出的函数,你别用错了
作者: lluct    时间: 2004-03-01 09:34
标题: 干嘛不给用getch(),gets()函数???
gets:
/tmp/cc3SSYvm.o(.text+0x40): In function `main':
: the `gets' function is dangerous and should not be used.
作者: carol1980    时间: 2004-03-01 09:43
标题: 干嘛不给用getch(),gets()函数???
原帖由 "lluct" 发表:
gets:
/tmp/cc3SSYvm.o(.text+0x40): In function `main':
: the `gets' function is dangerous and should not be used.


  那就听话,别用了  :wink:
作者: BingbingNorth    时间: 2004-03-01 09:46
标题: 干嘛不给用getch(),gets()函数???
hi,carol1980,好久没有看到你了。
lluct兄:
那只是一个警告而已,不过还是用fgets()代替gets()吧,gets()是一个过时的函数。
作者: win_hate    时间: 2004-03-01 10:36
标题: 干嘛不给用getch(),gets()函数???
gets 有缺陷,容易受到缓冲区溢出攻击, 所以编译器警告你.
如楼上所说, 用 fgets 比较好.




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2