vc 关于gets()和scanf

来源:百度知道 编辑:UC知道 时间:2024/06/21 14:33:27
定义了char name【10】;用scanf(“%s",name)可以输入,但是gets(name)程序就自动终止,显示错误,这是为什么呢?
不是溢出问题,我能肯定没有溢出哑

没有错啊 你试试我这个简单的程序 根据你那写的
#include <iostream.h>
#include <stdio.h>
int main()
{
cout<<"请输入姓名!"<<endl;
char name[10];//用scanf(“%s",name)可以输入,但是
gets(name);
cout<<name<<endl;
return 0;
}

注意:输入的不要太长!

#include <stdio.h>

void main( void )
{
char line[81];

printf( "Input a string: " );
gets( line );
printf( "The line entered was: %s\n", line );
}

这个是其的应用,你看你是不是那个地方弄错了

char name[10] 这里改大点 比如 char name[255] 不然会溢出

溢出了吧