绝望的scanf(或者我绝望:)) [英] hopeless scanf (or I'm hopeless :))

查看:66
本文介绍了绝望的scanf(或者我绝望:))的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

我有以下指示:

char wyp;

scanf("%c"& wyp) ;


这个scanf在一个while循环中,我希望它每次都能得到一个字符



有谁知道怎么做?

顺便说一句。如何获取有关输入和分配了多少字符的信息

到变量wyp?


也许有人有不同的想法从
键盘,不一定使用scanf。


提前感谢您的想法,


问候,

Chris Rutczynsky

Hi!
I have the following instruction:
char wyp;
scanf("%c",&wyp);

this scanf is in a while loop, and I want it to get EXACTLY one character
each time.
Does anyone knows how to do it?
BTW. How can I get information how many characters were entered and assigned
to variable wyp?

Maybe someone has a different idea to read excatly one character from
keyboard, not necessarily using scanf.

Thanks in advance for your ideas,

Regards,
Chris Rutczynsky

推荐答案

Kris写道:
Kris wrote:
嗨!
我有以下说明:
char wyp;
scanf("%c"& wyp);


这是一个声明。没有说明在C.

这个scanf是一个while循环,我希望它每次都能得到一个完整的角色。


这似乎是你的scanf声明会做的。

有谁知道怎么做?
BTW。如何获取有关输入和分配给变量wyp的字符数的信息?


来自scanf的返回值将告诉您转换了多少项目

并已分配。在上面的示例中,这将始终为1(除非发生

错误)。


wyp是一个char变量 - 它只能容纳一个字符一个

的时间。计算scanf成功执行的次数,

将告诉你已经为wyp分配了多少个字符。请注意,

只有最新的角色仍然存在。

也许有人有不同的想法从键盘上读取一个字符,不一定使用scanf。
Hi!
I have the following instruction:
char wyp;
scanf("%c",&wyp);
That''s a statement. There are no "instructions" in C.

this scanf is in a while loop, and I want it to get EXACTLY one character
each time.
That seems to be what your scanf statement will do.
Does anyone knows how to do it?
BTW. How can I get information how many characters were entered and assigned
to variable wyp?
The return value from scanf will tell you how many items were converted
and assigned. This will always be 1 in the example above (unless an
error occurs).

wyp is a single char variable - it can only hold one character at a
time. Count how many times the scanf is successfully executed, and that
will tell you how many characters have been assigned to wyp. Note that
only the most recent character is still there.

Maybe someone has a different idea to read excatly one character from
keyboard, not necessarily using scanf.




C语言不支持键盘的概念。所有I / O都在
流的条款中。输入是行缓冲的,因此在按Enter键之前程序不会看到你的键盘输入。换句话说,没有

标准方式来读取一次击键(除非击键发生在

为Enter)。


-Kevin

-

我的电子邮件地址有效,但会定期更改。

要联系我,请使用最近的地址发布。



The C language does not support the concept of keyboards. All I/O is in
terms of streams. Input is line-buffered, so the program won''t see your
keyboard input until you press Enter. In other words, there is no
standard way to read a single keystroke (unless the keystroke happens to
be Enter).

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.


On Tue,2003年11月25日02:23:55 +0100,Kris。 < RU *** @ wp.pl>写道:
On Tue, 25 Nov 2003 02:23:55 +0100, "Kris" <ru***@wp.pl> wrote:
嗨!
我有以下指示:
char wyp;
scanf("%c",& wyp);

这个scanf是一个while循环,我希望每次都能得到一个完整的角色。
有谁知道怎么做?


scanf("%c"& wyp);


将从stdin读取一个字符并将其存储到wyp。如果发生读取

错误或文件结束,scanf将返回0并且

将不会存储到wyp中。


你有什么问题,为什么你没希望?

也许有人有不同的想法从键盘上读取一个字符,不一定使用scanf。
Hi!
I have the following instruction:
char wyp;
scanf("%c",&wyp);

this scanf is in a while loop, and I want it to get EXACTLY one character
each time.
Does anyone knows how to do it?
scanf("%c",&wyp);

will read one character from stdin and store it to wyp. If a read
error occurred or the end of file is reached scanf will return 0 and
nothing will be stored to wyp.

What is your problem and why are you hopeless?
Maybe someone has a different idea to read excatly one character from
keyboard, not necessarily using scanf.




int c:


c = getchar();


if(c == EOF){/ *到达文件末尾或读取错误

发生* /}

从stdin中读取一个字符。如果到达文件末尾或发生

读取错误,则getchar返回EOF(这不是*一个字符)。


-

Horst



int c:

c = getchar();

if (c==EOF) { /* Either the end of file is reached or a read error
occured */ }

reads one character from stdin. If the end of file is reached or a
read error occured, getchar returns EOF (this is *not* a character).

--
Horst


Horst Kraemer写道:
Horst Kraemer wrote:
2003年11月25日星期二02: 23:55 +0100,Kris < RU *** @ wp.pl>写道:

On Tue, 25 Nov 2003 02:23:55 +0100, "Kris" <ru***@wp.pl> wrote:

嗨!
我有以下指示:
char wyp;
scanf("%c"& amp; ; wyp);

这个scanf是一个while循环,我希望每次都能得到一个字符

有谁知道怎么做?
Hi!
I have the following instruction:
char wyp;
scanf("%c",&wyp);

this scanf is in a while loop, and I want it to get EXACTLY one character
each time.
Does anyone knows how to do it?



scanf("%c"& wyp);

将从stdin读取一个字符并将其存储到wyp。如果发生读取错误或文件结束,则scanf将返回0并且
将不会存储任何内容。


scanf("%c",&wyp);

will read one character from stdin and store it to wyp. If a read
error occurred or the end of file is reached scanf will return 0 and
nothing will be stored to wyp.




我相信如果到达文件末尾,它将返回EOF。


-Kevin

-

我的电子邮件地址有效,但是定期更改。

要联系我,请使用最近发布的地址。



I believe it will return EOF if end of file is reached.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.


这篇关于绝望的scanf(或者我绝望:))的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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