ChinaUnix.net
相关文章推荐:

linux gets

我写的c程序在gcc编译时提示 gets危险, 我想问问大家怎么得到终端的字符串输入的. 我换了如下的做法代替gets, 不知道好不好 char buf[128]; fgets (buf, 128, stdin); buf [strlen(buf)] = '\0';

by xxandxx - 程序开发 - 2005-12-12 23:11:19 阅读(504) 回复(1)

相关讨论

#include #include main() { char buf[33][11]; for(i=0;i<3;i++) gets(buf); printf("*%c*\n",buf[1][1]); } 输入: woshi(回车) (回车) haichong(回车) 输出: *? 这是怎么回事啊?gets收都回车的时候会怎么做啊?

by 我是害虫 - C/C++ - 2008-03-10 23:46:29 阅读(1344) 回复(5)

我再linux用gcc编译c程序的时候,用gets函数的话,就老是给我下面的警告信息: /tmp/ccyhTLKy.o(.text+0x53): In function `main': : the `gets' function is dangerous and should not be used. 这是怎么会事啊? 不用gets,用scanf的话,读字符串,到空格就结束了.怎么改呢?

by aero - C/C++ - 2004-03-04 15:58:27 阅读(1277) 回复(2)

先看两个程序和其输出结果:) 程序一: [code] #include int main() { char buffer[100]; int n, i; if (gets(buffer) != NULL) { n = strlen(buffer); printf("the stelen of buffer is %d\n", n); for (i = 0; i <= n; i++) { printf("buffer[%d] is %d\n", i, buffer); ...

by 喇嘛疤瘌 - C/C++ - 2006-11-16 12:31:36 阅读(2853) 回复(7)

代码如下: cc=gets if cc==1 puts "Try again" elsif cc==11 puts "You lose" else puts "Enter anumber" end 输出结果: 应该会判断cc的输入值然后按照if的判断做出不同的puts输出才对,但是执行后发现,对gets的赋值if好像根本就没感觉到,无论你键盘给cc赋任何值,结果都是打印出Enter anumber。 为什么?

by coffee_45 - Ruby - 2009-07-02 15:25:33 阅读(6336) 回复(9)

char str1[20]; char str2[20]; char str3; gets(str1); scanf("%s",str2); 当通过gets(str1)输入完字符串,然后回车。这时回车符会转换为'\0',但scanf("%s",str2)在输入完字符串后,按回车,scanf("%s",str2)不会将回车符转换为'\0'。如果紧接着有scanf("%c",&str3),那么回车符会赋给str3;如果没有scanf("%c",&str3),那么这个回车符停留在哪里?对后面的输入有影响吗? [ 本帖最后由 光速 于 2008-12-25 22:41 编辑 ]

by 光速 - C/C++ - 2008-12-26 09:09:02 阅读(1328) 回复(7)

近日翻阅,它上面提到了gets的问题。 既然gets()的使用存在很大隐患,为什么ANSI C没有将它从标准库中拿掉呢?大家在平常写程序的时候用不用它? 我感觉他还是很方便的:em02: :em02:

by ruoyisiyu - C/C++ - 2007-09-01 14:33:46 阅读(2827) 回复(15)

下面是一个测试程序, #include #include main() { char *str1,*str2; printf("input two string\n"); gets(str1); gets(str2); puts(str1); puts(str2); } 当我运行的时候,出现错误如图,为何啊?

by ballfan_123 - C/C++ - 2006-08-17 14:42:44 阅读(3318) 回复(20)

Input(struct student *p){ struct student *a; for(a=p;agets(a->num); printf("Name:");gets(a->name); scanf("%d,%d,%d",&(a->score[0]),&(a->score[1]),&(a->score[2])); a->ave_score= (a->score[0]+ a->score[1]+ a->score[2])/3; printf("Now enter one data is off\n"); printf("...

by linuxshe - C/C++ - 2006-01-24 22:15:20 阅读(921) 回复(2)