问题标签 [putchar]

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 投票
5 回答
1414 浏览

c++ - 从 getchar 读取输入

每当我必须以这种方式使用 getchar 时,它也接受 enter 作为输入之一,因此我只能输入三个字符而不是 6 个字符。为什么 getchar 将 enter 作为输入之一?如何避免这种情况?

输入:

在此循环中断后,因为按下的三个返回被视为 temp[1]、temp[3] 和 temp[5] 的三个输入。

0 投票
4 回答
152 浏览

c - 使用 c 中的 getchar()

我知道getchar()缓冲字符。如果我执行这个程序并输入一些字符Hello而不按回车键我按下EOF字符为什么它Hello再次打印并要求新字符?

0 投票
4 回答
5297 浏览

c - putchar('0' + num); 是什么意思?做?

我试图了解它是如何putchar('0' + r);工作的。下面,该函数接受一个整数并将其转换为二进制。

我用谷歌搜索putchar的定义,但没有找到。为了测试它,我添加了一个 printf 来查看 r 的值:

我运行它(输入 5)并得到这个输出:

r = 1 和 putchar 打印 1
r = 0 和 putchar 打印 0
r = 1 和 putchar 打印 1

所以我想putchar('0' + r); 如果 r=0 打印 0,如果 r=1 打印 1,或者发生其他事情?

0 投票
2 回答
112 浏览

c - 按位运算,位的打印取决于首先放置哪个 putchar ......?

我只是想将一个无符号整数打印为位,但它似乎是我的代码:

仅当 if 语句这样更改(替换 1 和 0)时才有效:

我不知道为什么会这样……有什么想法吗?

谢谢

0 投票
2 回答
95 浏览

c - 谁能解释一下代码 putchar('/' //*/ 1) 的含义

我在做K&R2的练习。当我在此页面http://clc-wiki.net/wiki/K%26R2_solutions:Chapter_1:Exercise_23阅读 Ben Pfaff 的代码时, 我无法理解单个代码 putchar('/' //*/ 1 ) 意思是。在我的编译器中,这是一个语法错误。所以任何人都可以向我解释这一点。

0 投票
2 回答
5757 浏览

c - 仅使用 putchar 在 c 中打印一个整数

这是一种古老的做法,我试图找出我的代码哪里出错了:编写 ac 程序以仅使用 putchar 打印一个整数。我知道一种正确的方法是:

我只是想知道为什么我的方法不起作用,尽管当我尝试使用 step over 进行调试时,看起来我的程序没有问题,但是,代码正在打印一些有趣的字符。我认为这是因为 putchar() 将数字读取为 ascii 值并打印与 ascii 值对应的字符,也许这就是为什么在上面的代码中,我们使用putchar(n%10+'0'),所以我尝试添加'0'到我所有的 putchar 代码中,但是它不能正常工作。所以这是我的代码和结果,'0'当 i=-123 时没有和

在此处输入图像描述

在此处输入图像描述

0 投票
1 回答
1233 浏览

c - Trying to output user input with only getchar/putchar

I have to write a simple calculator in C, that only uses getchar/putchar. I need to echo the user input, and then perform the mathematical operation (only need to use +, /, %, *, and -). Right now, I only care about what I'm doing wrong, as far as storing the values into my input variables. The rest of the program should be fairly easy to do myself.

In my while loop, I tried to be careful with nesting if/else's (mainly for error-checking purposes) only inside my "else if's". I want my loop to ignore spaces, and then assign the number, math operator, and other number into input1, input2, and input3, respectively. Right now, if I input something like "55 * 66", I am returned something like "*0".

Thanks for looking.

UPDATE (3/22/2014): I'm getting a little bit closer. My problem right now is that the program will only work when I input one space after each number and operand (i.e. "2 + 4" works, but anything without spaces, or with more than one space, does not). I also didn't quite get how to putchar the numbers to output them. I used printf so I could at least have a working program, in the mean time. Thanks.

0 投票
7 回答
5468 浏览

c - C 编程语言,第 1 章练习 1.10(Getchar 和 Putchar)

我已经为此工作了 2 个小时,但我被困住了……我在网上找到了答案,但这并不能帮助我了解我显然遗漏的概念。

提示:编写一个程序,将其输入复制到其输出,将每个制表符替换为\t,每个退格替换为\b,每个反斜杠替换为\\。这使得制表符和退格键以明确的方式可见。

这是我想出的,它不会替换 a tabor\与指定的putchar,它只是在它前面添加它。(我没有做退格,因为我不能真正输入退格......):

这就是我阅读代码的方式。我错过了什么?:

“有一些整数cc等于输入。当输入不等于文件结尾时继续。如果输入是制表符,则输出\t。如果输入是\输出\\。将输入输出到控制台。”

0 投票
2 回答
1815 浏览

c++ - getchar() 或 putchar() 一直在吃我输入的第一个字符

编辑:这个问题解决了。谢谢你的所有答案

这是我的程序:

每次我运行它时,它都可以正常工作,但是会吃掉我输入的第一个字符,例如当我运行程序时,输出如下所示:

“t”不见了。为什么会发生这种情况,我该如何解决?

感谢您的时间。

0 投票
5 回答
27785 浏览

c - putchar() 与 printf() - 有区别吗?

我目前在第 1.5.1 章文件复制中,并制作了这样的程序:

如果我这样运行它:

输出就是我输入的。

这是我为实验目的制作的一个程序:

putchar它产生相同的结果,但和之间有区别printf吗?

两者之间哪个更好用?