使用Enter键作为用户控制的程序流程 [英] Using Enter key as user-controlled program flow

查看:83
本文介绍了使用Enter键作为用户控制的程序流程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我想找到一种使用scanf()的方法,而Enter键是

有用户控制的程序流程。目前,我的程序中有几行

行,这可以作为程序中的暂停。

printf(" \ n\tTo继续,按任意键后跟Enter:");

scanf("%i"& temp);


这可以作为程序暂停,但是它要求用户输入

键加上输入。有没有办法使用scanf(),以便用户只需要
需要使用Enter键?或者是否有比这更好的功能?

scanf()用于此目的?


谢谢,

Andrew
< br>

Hello,
I would like to find a way of using scanf() and the Enter key to
have user-controlled program flow. Currently, I have a couple of
lines in my program which serves as a pause in the program.
printf("\n\tTo continue, press any key followed by Enter: ");
scanf("%i",&temp);

This works as a program pause, but it requires that the user enter a
key plus enter. Is there a way to use scanf() so that the user only
needs to use the Enter key? Or is there a better function than
scanf() for this purpose?

thanks,
Andrew

推荐答案

Andrew Gentile写道:
Andrew Gentile wrote:

你好,

我想找到一种方法,使用scanf()和Enter键来确定用户控制的程序流程。目前,我的程序中有几行

行,这可以作为程序暂停。


printf(" \ n\tTo继续,按任意键,然后按Enter:");

scanf("%i",& temp);


这可用作程序暂停,但它要求用户输入

键加上输入。有没有办法使用scanf(),以便用户只需要
需要使用Enter键?或者是否有比这更好的功能?

scanf()用于此目的?


谢谢,

Andrew
Hello,
I would like to find a way of using scanf() and the Enter key to
have user-controlled program flow. Currently, I have a couple of
lines in my program which serves as a pause in the program.
printf("\n\tTo continue, press any key followed by Enter: ");
scanf("%i",&temp);

This works as a program pause, but it requires that the user enter a
key plus enter. Is there a way to use scanf() so that the user only
needs to use the Enter key? Or is there a better function than
scanf() for this purpose?

thanks,
Andrew



char n;

fgets(& n,1,stdin);

char n;
fgets(&n, 1, stdin);


文章< 11 ************* @ news-west.n>,

Christopher Layne< cl **** @ com.anodizedwrote:
In article <11*************@news-west.n>,
Christopher Layne <cl****@com.anodizedwrote:

> Andrew Gentile写道:
>Andrew Gentile wrote:

>你好,
我想找个办法使用scanf()和Enter键来实现用户控制的程序流程。目前,我的程序中有几行
,作为程序中的暂停。

printf(" \ n \ t要继续,按任意键,然后按Enter键:");
scanf("%i"& temp);

这可以作为程序暂停,但它要求用户输入一个
键加上输入。有没有办法使用scanf(),以便用户只需要使用Enter键?或者是否有比
scanf()更好的功能?

谢谢,
Andrew
>Hello,
I would like to find a way of using scanf() and the Enter key to
have user-controlled program flow. Currently, I have a couple of
lines in my program which serves as a pause in the program.
printf("\n\tTo continue, press any key followed by Enter: ");
scanf("%i",&temp);

This works as a program pause, but it requires that the user enter a
key plus enter. Is there a way to use scanf() so that the user only
needs to use the Enter key? Or is there a better function than
scanf() for this purpose?

thanks,
Andrew


char n;
fgets(& n,1,stdin);


char n;
fgets(&n, 1, stdin);



我确定专业的挑剔者会有一两件事要说这个(b
)怎么会失败,为什么呢不是便携式的,等等),你必须承诺,对OP的问题的真实,规范的回答是(总是为

):


关闭主题。不便携。不能在这里讨论它。 Blah,等等,等等。

I''m sure the professional nitpickers will have a thing or two to say
about that (how it could fail, why it''s not portable, etc), you have to
admit that the real, canonical, answer to the OP''s question is (as
always):

Off topic. Not portable. Cant discuss it here. Blah, blah, blah.


Andrew Gentile写道:
Andrew Gentile wrote:

你好,

我想找到一种使用scanf()和Enter键的方式

有用户控制的程序流程。目前,我的程序中有几行

行,这可以作为程序暂停。


printf(" \ n\tTo继续,按任意键,然后按Enter:");

scanf("%i",& temp);


这可用作程序暂停,但它要求用户输入

键加上输入。有没有办法使用scanf(),以便用户只需要
需要使用Enter键?或者为了这个目的,有没有比

scanf()更好的功能?
Hello,
I would like to find a way of using scanf() and the Enter key to
have user-controlled program flow. Currently, I have a couple of
lines in my program which serves as a pause in the program.
printf("\n\tTo continue, press any key followed by Enter: ");
scanf("%i",&temp);

This works as a program pause, but it requires that the user enter a
key plus enter. Is there a way to use scanf() so that the user only
needs to use the Enter key? Or is there a better function than
scanf() for this purpose?



虽然你可以使用scanf()来实现这个目的,但更简单的函数如

getchar(),getc()或fgetc()会更合适。


int c;

fputs(" \ n\tt继续,按Enter ... \ n", stdout);

c = getc(stdin);


你必须确保输入中没有待处理的字符

stream'的缓冲区。否则,对getc()的调用将读取这些,

而不是阻止来自键盘的输入。

Though you can use scanf() for this purpose, a simpler function like
getchar(), getc() or fgetc() would be more suitable.

int c;
fputs("\n\tTo continue, press Enter...\n", stdout);
c = getc(stdin);

You''ll have to ensure that there''re no characters pending in the input
stream''s buffers. Otherwise, the call to getc() will read those,
instead of blocking for input from the keyboard.


这篇关于使用Enter键作为用户控制的程序流程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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