字符串操作scanf与gets的区别

在c语言中对于字符串的输入

scanf

char str[20];
scanf("%s",str);

gets

char str[20];
gets(str);

区别:

1. scanf不能获取空格之后的字符串 

例如:

"how are you" 

使用scanf("%s",str)只能获取到 "how"

但是使用gets(str) 能获取到 "how are you"

你可能感兴趣的:(C++,c++,c语言)