Linux下gets无法使用
如下代码,GCC无法编译:#include <stdio.h>#include <string.h>int main(){char str[200],ch;char *p,*q;gets(str);//fgets(str,200,stdin);p=str;q=p+strlen(p) -1;wh...
·
如下代码,GCC无法编译:
#include <stdio.h>
#include <string.h>
int main()
{
char str[200],ch;
char *p,*q;
gets(str);
//fgets(str,200,stdin);
p=str;
q=p+strlen(p) -1;
while(p<q)
{
ch=*p;
*p++=*q;
*q--=ch;
}
printf("%s\n",str);
}
error: ‘gets’ was not declared in this scope
gets (str);
^~~~
解决办法:
fgets(str,字符串最大长度n,stdin);
#include <stdio.h>
#include <string.h>
int main()
{
char str[200],ch;
char *p,*q;
fgets(str,200,stdin);
p=str;
q=p+strlen(p) -1;
while(p<q)
{
ch=*p;
*p++=*q;
*q--=ch;
}
printf("%s\n",str);
}
I am very shengqi
iqgnehs yrev ma I
更多推荐
已为社区贡献1条内容
所有评论(0)