#define N 80
int del(char *p,char x)
{ char *q=p;
for(;*p!='\0';p++)
if(*p!=x)
*q++=*p;
*q='\0';
}
int main()
{ char c[N],*pt=c,x;
printf("enter a string:");
gets(c);
printf("\n");
printf("enter the char deleted:");
x=getchar();
del(pt,x);
printf("the new string is:%s\n",c);
}
程序如上,可以正常运行,但编译时出现这样的警告 warning: the `gets' function is dangerous and should not be used.
为什么阿,


ShinyGuo 于 2009-04-02 23:37:05发表:
因为gets()对输入字符的个数没有限制,所以可能造成缓冲区溢出。应该避免使用它并用fgets()代替。
char *fgets(char *s, int n, FILE *stream);
----cite from
heiyie 于 2009-04-02 22:36:06发表:
谢谢,那为什么又可以运行么,且好像能输入字符串阿
wang7131984 于 2009-04-01 22:43:03发表:
Linux 下gcc编译器不支持gets这个函数