c语言 scanf函数的问题? C语言关于scanf函数的问题?

C\u8bed\u8a00\u4e2d\u5173\u4e8escanf\uff08\uff09\u51fd\u6570\u5206\u9694\u7b26\u95ee\u9898\uff1f

scanf\u4e0d\u6307\u5b9a\u5206\u5272\u7b26\u53f7\u65f6\uff0c\u9ed8\u8ba4\u4ee5\u7a7a\u683c\u3001\u56de\u8f66\u3001\u5236\u8868\u7b26\uff08tab\uff09\uff0c\u4f5c\u4e3a\u5206\u5272\u7b26\u53f7\uff0c\u53ef\u95f4\u9694\u591a\u4e2a\u5206\u5272\u7b26\u53f7\u3002
\u81f3\u4e8e\u4f60\u6700\u540e\u6253\u5370\u7684c\uff0c\u90a3\u662f\u6362\u884c\u7b26\u5bf9\u5e94\u7684ascii\u7801\uff0c\u56e0\u4e3a\u4f60\u6700\u540e\u8f93\u5165\u7684\u5b57\u7b26\u662f\u56de\u8f66\u3002

\u7b54\uff1ascanf()\u7684\u529f\u80fd\u662f\u4ece\u952e\u76d8\u83b7\u53d6\u6570\u636e\u8d4b\u503c\u7ed9\u5bf9\u5e94\u7684\u53d8\u91cf\uff0c\u62ec\u53f7\u5185\u5305\u62ec\u8f93\u5165\u63a7\u5236\u7b26\u548c\u8f93\u5165\u53c2\u6570\u4e24\u90e8\u5206\u3002
\u4ece\u952e\u76d8\u8f93\u5165\u7684\u6570\u636e\u9700\u8981\u8f6c\u5316\u6210\u8f93\u5165\u63a7\u5236\u7b26\u7684\u683c\u5f0f\u6570\u636e\uff0c\u7136\u540e\u5b58\u5165\u8f93\u5165\u53c2\u6570\u3002
scanf("%3d",&a);
\u662f\u901a\u8fc7\u5341\u8fdb\u5236\u6574\u65703\u6307\u5b9a\u8f93\u5165\u7684\u5bbd\u5ea6\uff0c\u5373\u5b57\u7b26\u6570\uff0c\u8d85\u51fa\u90e8\u5206\u4e0d\u8d4b\u503c\uff0c\u6545\u9898\u4e2d\u53ea\u628a123\u8d4b\u503c\u7ed9a\u3002
scanf("%3c",&ch);
\u901a\u5e38%3c\u53ef\u4ee5\u7528\u6765\u8bfb\u5165\u4e09\u4e2a\u8fde\u7eed\u7684\u5b57\u7b26\uff0c\u7531\u4e8e\u8fd9\u91ccch\u662f\u4e00\u4e2a\u53d8\u91cf\uff0c\u800c\u4e0d\u662f\u4e00\u4e2a\u6570\u7ec4\uff0c\u6240\u4ee5\u53ea\u80fd\u653e\u4e0b\u4e00\u4e2a\u5b57\u7b26\uff0c\u5373\u9898\u4e2d\u5c064\u4f5c\u4e3a\u4e00\u4e2a\u5b57\u7b26\u578b\u6570\u636e\uff0c\u8d4b\u503c\u7ed9ch\u53d8\u91cf\u3002
\u8d85\u51fa\u7684\u90e8\u5206\u6ca1\u6709\u88ab\u4fdd\u5b58\uff0c\u6240\u4ee5\u4e0d\u663e\u793a\u3002
\u5982\u679c\u6709\u4e0d\u61c2\u7684\uff0c\u53ef\u4ee5\u7ee7\u7eed\u63d0\u95ee\u3002

scanf("%c",&a);等价于a
=
getchar();他们共同点就是可以读取空格'
'与换行符('\n'),所以你输入y后按空格或回车,然后a为空格或回车,然后就退出do
while了

扩展阅读:c语言第二次scanf有问题 ... c语言printf输出格式 ... 5个例子搞懂scanf ... c语言scanf循环读取 ... c语言scanf用法举例 ... c语言中scanf s怎么声明 ... c语言scanf输入汉字 ... scanf的简单例子 ... c语言中scanf的用法及规则 ...

本站交流只代表网友个人观点,与本站立场无关
欢迎反馈与建议,请联系电邮
2024© 车视网