问题标签 [gets]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
4836 浏览

ruby - 使用gets命令在Ruby中按字母顺序对数组进行排序

我是一个 Ruby 菜鸟,我只是尝试使用 gets 命令对一组单词(“dog”、“cat”、“ape”)进行排序,这些单词应该由 gets 单独输入并成为(“ape”、“cat”、 “狗”)

我试过了:

任何帮助都会很棒,因为这可以帮助我女儿更快地整理作业并学习打字。

0 投票
3 回答
1057 浏览

ruby - 在 Ruby 中,我如何将睡眠与获取结合起来?我想等待用户响应 1 分钟,否则继续

我正在运行一个循环,在其中我使用“gets.chomp”命令等待用户响应。如何将它与睡眠/定时器命令结合使用?

例如。我希望它等待 1 分钟让用户输入一个单词,否则它将继续返回循环。

0 投票
2 回答
569 浏览

ruby - 程序终止后,Ruby 将输入转到控制台命令行

我正在尝试设置一个带有两个附加线程的简单 ruby​​ 程序。

  • 一个线程是检查串行端口的数据并在找到任何内容时填充变量。

  • 第二个线程是对“gets”的调用,返回时将停止程序。

  • 主线程只是将第一个附加线程存储的值输出到控制台(该程序是基于控制台的数据记录器)。

我的问题是第二个线程启动正常,正如您从输出中的“Press Enter ...”注释中看到的那样。

但从返回的任何数据

输入=得到

没有进入程序。相反,它可以在使用 ctrl-c 杀死程序后在控制台命令行上看到。

我在 Windows 上的 ruby​​ 控制台中运行它。这以前可以正常工作,但我在某一点重新安排了代码,现在它不合作了。我已经复制了下面的整个程序。我想这是非常简单的事情,但我完全被卡住了,所以谢谢你看一看。

乔恩

0 投票
2 回答
1182 浏览

c - How can I scan strings with multiple words multiple times in C [not C++]?

I have googled many times but I cannot find a concrete answer to my question/problem. I know fgets() allows it, as well as gets(). But if i do it multiple times, there's always an error. Multiple times mean, e.g. I want to ask for his first name, then his middle name, then his surname which can be 1 or more strings.

I think I got it by using gets since I can't make fgets() work, but there's some bug in my program. So, I wanna ask for a better solution than what I did. Anyway, here's the partial code:

The bug is that if I entered an invalid number in add.Let's say I input 5 in employee number but there's employee number 5 already, the program will say that there's already employee 5 but if i print the employee list employee 5 is not there. Entering 5 again in add will not prompt you because it deleted employee 5. I do not how it is deleted since i did not call the delete function. Please someone help me.

edit: I removed checknum and did the search in my search function for delete: my code for search is:

and add is now:

I think the problem now lies on what it returns to root when it encounters an "invalid input." I call add() by root=add(root) so if it encountered a problem it points to null or something else. So what do you think must I do?

EDIT [LAST]: The problem really lies in what add() returns if it encountered the "invalid input." I changed BST *add to void add to avoid the root=add(root) then did the necessary changes in the function and now it works. Thanks for your answers, but I cannot give a check mark since I think no one answered it right. I'm now making it go with fgets().

0 投票
4 回答
541 浏览

buffer - scanf 并获取缓冲区

我遇到了 scanf 和 get 的问题。我知道它一定会出错,但我找不到其他方法。这样,名称会打印出来,但不会打印出它的第一个字母。这是我的代码:

样本输出:

0 投票
6 回答
6385 浏览

c - 在 C 中读取字符串

如果我使用 C 获取(),并且我正在从用户那里读取一个字符串,但我不知道我需要多大的缓冲区,并且输入可能非常大。有没有办法可以确定用户输入的字符串有多大,然后分配内存,然后将其放入变量中?或者至少是一种在不知道输入有多大的情况下接受输入的方法,它可能不适合我已经分配的缓冲区。

0 投票
2 回答
2410 浏览

c - Gets(string#) 函数跳过首先获取请求

我正在为我自己的个人休闲和学习做一个项目。它的一部分看起来像这样:

我的问题是输出跳过了第一个“gets(string#)”并继续到下一个“printf()”。有人能告诉我这是为什么吗?

0 投票
1 回答
2731 浏览

c - 获取()的问题

我正在尝试获取输入数据并使用结构打印它。当我运行此代码时,它不会输入姓氏。它直接要求输入名字的输入。有人可以帮我弄这个吗。谢谢你。

当我运行它时,它不会等待输入姓氏。它直接去输入名字。

0 投票
5 回答
5520 浏览

c++ - gets() 被正式弃用了吗?

基于最新的 C++11 草案,C++ 参考 ISO/IEC 9899:1999/Cor.3:2007(E) 来定义 C 库函数(根据 §1.2[intro.refs]/1) .

基于 C99 TC3 的最新草案The gets function is obsolescent, and is deprecated.(根据 §7.26.9/2)

我可以肯定地说gets()在 C 和 C++ 中都已弃用它吗?

0 投票
1 回答
703 浏览

ruby - 在 Ruby 中从命令行读取时更改获取的行为

下面 Ruby 代码的预期操作如下:

  1. 将命令行命名的文件 ARGV[0] 写入 old
  2. 创建该文件的新临时副本
  3. 循环直到用户给出输入
  4. 删除临时文件

当我硬编码等于 hello.c 的旧代码时,do 循环中的超时按我的预期工作:它等待 3 秒以等待来自键盘的输入,如果没有给出输入救援块并重复。

当我将 old 设置为 ARGV[0](也是 hello.c)时,将 fp 分配给 hello.c 的第一行,并且代码会跳出循环。

我如何运行它:

编码:

我不明白为什么从命令行读取与硬编码文件名有什么不同。

感谢您提供的任何帮助。谢谢。