<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>getchar</title>
	<atom:link href="https://www.aitaocui.cn/tag/151445/feed" rel="self" type="application/rss+xml" />
	<link>https://www.aitaocui.cn</link>
	<description>翡翠玉石爱好者聚集地</description>
	<lastBuildDate>Tue, 22 Nov 2022 10:29:18 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.1</generator>

<image>
	<url>https://www.aitaocui.cn/wp-content/uploads/2022/11/taocui.png</url>
	<title>getchar</title>
	<link>https://www.aitaocui.cn</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>getchar(计算机语言函数)</title>
		<link>https://www.aitaocui.cn/article/239853.html</link>
					<comments>https://www.aitaocui.cn/article/239853.html#respond</comments>
		
		<dc:creator><![CDATA[留下来陪你生活]]></dc:creator>
		<pubDate>Tue, 22 Nov 2022 10:29:18 +0000</pubDate>
				<category><![CDATA[百科]]></category>
		<category><![CDATA[getchar]]></category>
		<guid isPermaLink="false">https://www.aitaocui.cn/?p=239853</guid>

					<description><![CDATA[getchar是读入函数的一种。它从标准输入里读取下一个字符，相当于getc(stdin)。返回类型为int型，为用户输入的ASCII码或EOF。 描述 C库函数int getch...]]></description>
										<content:encoded><![CDATA[</p>
<article>
<p>getchar是读入函数的一种。它从标准输入里读取下一个字符，相当于getc(stdin)。返回类型为int型，为用户输入的ASCII码或EOF。</p>
</article>
<article>
<h1>描述</h1>
<p>C库函数int getchar(void)从标准输入stdin获取一个字符（一个无符号字符）。这等同于getc带有stdin作为参数。</p>
<h1>声明</h1>
<p>int getchar(void)</p>
<h1>返回值</h1>
<p>函数的返回值为用户输入的第一个字符的ASCII码，若出错返回-1，且将用户输入的字符回显到屏幕。如果用户在按回车键之前输入了不只一个字符，其他字符会保留在键盘缓冲区中，等待后续getchar()调用读取。也就是说，后续的getchat()调用不会等待用户按键，而是直接读取缓冲区中的字符，直到缓冲区的字符读取完毕后，才等待用户按键。</p>
<h1>说明</h1>
<p>getchar()非真正函数，而是getc(stdin)宏定义。</p>
<h1>程序例</h1>
<p>例1</p>
<p>#include</p>
<p>int main(void)</p>
<p>{</p>
<p>int c;</p>
<p>/* Note that getchar reads from stdin and</p>
<p>is line buffered; this means it will</p>
<p>not return until you press ENTER. */</p>
<p>while ((c = getchar()) != &#x27;//n&#x27;)</p>
<p>printf(&quot;%c&quot;, c);</p>
<p>return 0;</p>
<p>}</p>
<p>注：可以利用getchar()函数让程序调试运行结束后等待编程者按下键盘才返回编辑界面，用法：在主函数结尾，return 0；之前加上getchar();</p>
<p>例2</p>
<p>#include </p>
<p>int main()</p>
<p>{</p>
<p>char a,b;</p>
<p>a=getchar();</p>
<p>b=getchar();</p>
<p>putchar(a);</p>
<p>putchar(b);</p>
<p>}</p>
<p>我们输入x-回车-y-回车</p>
<p>结果会是xy吗？不是的，结果是a=x b=&#x27;//n&#x27;(回车)</p>
<p>当我们开始打x的时候，x在缓冲区，当我们按下回车的时候，第一个getchar()才获取到x这个值顺利存到a里，但回车既是确定又是字符，回车&#x27;//n&#x27;它也跟着进了缓冲区，并且和x一起被释放，x到了程序里，回车（&#x27;//n&#x27;）也到了程序里，并且被第2个getchar（）获取，此时我们输入y，这时缓冲区里有一个字符&#x27;y&#x27;,然后我们又按下回车，&#x27;y&#x27;和&#x27;//n&#x27;又一起准备被释放，由于程序里没有第3个getchar(),所以&#x27;y&#x27;和&#x27;//n&#x27;还留在缓冲区，但它们两个已经是在准备状态中，如果程序又出现一个getchar(),&#x27;y&#x27;不需要你按回车它会直接进入到第3个getchar()，getchar()是依次获取，按先后顺序，不会先获取&#x27;//n&#x27;,而&#x27;//n&#x27;正等待着马上进入第4个getchar()</p>
</article>
<div class="mt-3 mb-3" style="max-width: 770px;height: auto;">
                                    </div>
<div class="mt-3 mb-3" style="max-width: 770px;height: auto;">
                                    </div>
<div class="mt-3 mb-3" style="max-width: 770px;height: auto;">
                                    </div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.aitaocui.cn/article/239853.html/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
