只需按Enter键,如何使用scanf接受默认值? [英] How do I use scanf to accept a default value by simply pressing Enter key?

查看:146
本文介绍了只需按Enter键,如何使用scanf接受默认值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有人可以帮助我解决这个问题:

I was wondering if someone could please help me with this:

printf("Enter path for mount drive (/mnt/Projects) \n");
scanf("%s", &cMountDrivePath);  

是否可以允许用户仅按Enter键并接受默认值(在这种情况下为/mnt/Projects )? 目前,如果用户按Enter键,则光标仅跳到下一行,仍然需要输入.

Is it possible to allow the user to simply press Enter and accept the default (in this case: /mnt/Projects)? At present, if the user presses Enter, the cursor simply goes to the next line and input is still required.

我得到的印象 scanf 不允许这样做,在这种情况下,我应该使用什么?

I get the impression scanf does not allow this, in which case, what should I use?

谢谢!

推荐答案

我认为fgets()为您提供了更多的输入可能性,尤其是空白行.

I think fgets() gives you a bit more possibilities in input, especially blank lines.

这篇关于只需按Enter键,如何使用scanf接受默认值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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