我正在学习一些 C,并且正在阅读scanf
from 本教程 http://www.tutorialspoint.com/c_standard_library/c_function_scanf.htm其中包含以下代码块:
#include <stdio.h>
int main()
{
char str1[20], str2[30];
printf("Enter name: ");
scanf("%s", &str1);
printf("Enter your website name: ");
scanf("%s", &str2);
printf("Entered Name: %s\n", str1);
printf("Entered Website:%s", str2);
return(0);
}
但是我收到警告:
"Format specifies type 'char *' but the argument has type 'char (*)[20]'
教程有错吗?
这应该适合你:
#include <stdio.h>
int main()
{
char str1[20], str2[30];
printf("Enter name: ");
scanf("%19s", str1);
//^^ ^ Removed address operator
//So only the right amount of characters gets read
printf("Enter your website name: ");
scanf(" %29s", str2);
//^ Added space to catch line breaks from the buffer
printf("Entered Name: %s\n", str1);
printf("Entered Website:%s", str2);
return(0);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)