scanf函数不打印或阅读什么 [英] scanf not printing or reading anything

查看:155
本文介绍了scanf函数不打印或阅读什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下线在我的code:

I have the following line in my code:

char y[] = "a";
scanf("Letter: %s", y);
printf("%s\n", y);

第二行根本不影响第三线的输出。我已经包括<&stdio.h中GT; ,我想不出有什么不好...

The second line does not impact the output of the third line at all. I've included <stdio.h>, I can't think of what is wrong...

推荐答案

一个人做的最大的错误,是包括在引号之间的 scanf函数函数的字符串比格式规范(如%S %d个)的$ C $其他C应该 scanf函数(%S,Y)。如果你采取任何其他字符,那么你将不得不从头开始你的头找,找出问题。

One of the biggest mistakes one does, is to include any string in the scanf function between the quotes other than format specification(like %s or %d).The code should be scanf("%s",y).If you take any other character then you will have to scratch your head looking to find out problems.

(即使你有任何字符,那么你必须输入该字符,EG-如果你写 scanf函数(信:%S,Y); 然后上输入你必须写像 C:\\&GT;信:的信,你将进入的),这显然不是一个明智的想法。也在 scanf函数的功能是不是有打印出来的东西,它从terminal.To只是读取输入打印出来,你应该使用的printf(信 ); 就是这样

(Even if you include any character then you have to input that character,e.g- if you write scanf("letter: %s",y); then on input you have to write like C:\>letter: "letter which you will enter") which is obviously not a wise idea .Also the scanf function is not there to print things out, its just to read input from the terminal.To print out you should use printf("letter"); that's it.

只是假设你有使用一个 scanf()的则可以使用像 scanf函数(%D采取输入从两个int变量&放大器;一,和b); 你可以看到我已经把任何除引号格式规范

Just suppose you have to take inputs from two int variables using one scanf() then you will use like scanf("%d%d",&a,&b); as you can see i have put nothing except format specification in the quotes.

这篇关于scanf函数不打印或阅读什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆